PHP 4.0 Bug #3233: mysql_connect truncates $host variable passed in

From: Date: Mon, 17 Jan 2000 15:04:46 +0000
Subject: PHP 4.0 Bug #3233: mysql_connect truncates $host variable passed in
Groups: php.dev 
Request: Send a blank email to php-dev+get-14714@lists.php.net to get a copy of this message
From: cshenton@uucom.com Operating system: Solaris-5.6 Sparc PHP version: 4.0 Beta 3 PHP Bug Type: MySQL related Bug description: mysql_connect truncates $host variable passed in In php_mysql.c:444 If mysql_connect($host) is called and $host="foo:1234" then the variable $host will be truncated at the colon. The code jams a NULL at this position: if (host && (tmp=strchr(host,':'))) { *tmp=0; tmp++; port = atoi(tmp); } else { port = MySG(default_port); } I think the code should copy the host part of the string to a new variable rather than corrupting the user variable. <? $user="dbuser"; $passwd="dbpasswd"; $host='127.0.0.1:63306'; echo "host is \"$host\"<br>"; if (! $cid = mysql_connect($host,$user,$passwd)) { echo "FAIL connect($host,$user,$passwd): (" . mysql_error() . ") LOSER"; } else { echo "OK! host=\"$host\" WINNER"; } ?> And when I run the code, note below that the rest of the "echo" statement after the truncated host part is not rendered, due to the NULL in the string. Connecting manually to the server and going a HTTP GET shows the NULL in the string, but the string is still damaged. host is "127.0.0.1:63306" OK! host="127.0.0.1 This is also done in today's 4.0b CVS.

« previous php.dev (#14714) next »