From: Andrey Hristov Date: Mon, 6 Dec 2010 13:50:51 +0000 (+0000) Subject: don't crash if the API is used incorrectly X-Git-Tag: php-5.3.4~9 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=03fd10c479d7e45d8b622f0dafba616b19cc21b4;p=php don't crash if the API is used incorrectly --- diff --git a/ext/mysqlnd/mysqlnd.c b/ext/mysqlnd/mysqlnd.c index 6aa94e2e00..d4ccd00346 100644 --- a/ext/mysqlnd/mysqlnd.c +++ b/ext/mysqlnd/mysqlnd.c @@ -1971,15 +1971,19 @@ MYSQLND_METHOD(mysqlnd_conn, change_user)(MYSQLND * const conn, } } if (ret == PASS) { + char * tmp = NULL; + /* if we get conn->user as parameter and then we first free it, then estrndup it, we will crash */ + tmp = mnd_pestrndup(user, user_len, conn->persistent); if (conn->user) { mnd_pefree(conn->user, conn->persistent); } - conn->user = mnd_pestrndup(user, user_len, conn->persistent); + conn->user = tmp; + tmp = mnd_pestrdup(passwd, conn->persistent); if (conn->passwd) { mnd_pefree(conn->passwd, conn->persistent); } - conn->passwd = mnd_pestrdup(passwd, conn->persistent); + conn->passwd = tmp; if (conn->last_message) { mnd_pefree(conn->last_message, conn->persistent);