Skip to content

Commit e183ea0

Browse files
committed
don't crash if the API is used incorrectly
1 parent 3722811 commit e183ea0

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

ext/mysqlnd/mysqlnd.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1994,15 +1994,19 @@ MYSQLND_METHOD(mysqlnd_conn, change_user)(MYSQLND * const conn,
19941994
}
19951995
}
19961996
if (ret == PASS) {
1997+
char * tmp = NULL;
1998+
/* if we get conn->user as parameter and then we first free it, then estrndup it, we will crash */
1999+
tmp = mnd_pestrndup(user, user_len, conn->persistent);
19972000
if (conn->user) {
19982001
mnd_pefree(conn->user, conn->persistent);
19992002
}
2000-
conn->user = mnd_pestrndup(user, user_len, conn->persistent);
2003+
conn->user = tmp;
20012004

2005+
tmp = mnd_pestrdup(passwd, conn->persistent);
20022006
if (conn->passwd) {
20032007
mnd_pefree(conn->passwd, conn->persistent);
20042008
}
2005-
conn->passwd = mnd_pestrdup(passwd, conn->persistent);
2009+
conn->passwd = tmp;
20062010

20072011
if (conn->last_message) {
20082012
mnd_pefree(conn->last_message, conn->persistent);

0 commit comments

Comments
 (0)