php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #3233 mysql_connect truncates $host variable passed in
Submitted: 2000-01-17 10:04 UTC Modified: 2000-07-30 09:43 UTC
From: cshenton at uucom dot com Assigned:
Status: Closed Package: MySQL related
PHP Version: 4.0 Beta 3 OS: Solaris-5.6 Sparc
Private report: No CVE-ID: None
 [2000-01-17 10:04 UTC] cshenton at uucom dot com
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.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2000-07-30 09:43 UTC] zak@php.net
Cannot reproduce error.

If the problem occurs with the most recent release of php, please submit a new bug report.


Note: Did not test in solaris - I doubt that this is an OS specific bug. 
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon May 20 20:01:32 2024 UTC