php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #8951 php_mysql_do_connect -> parameter host modified when using port or socket
Submitted: 2001-01-27 12:46 UTC Modified: 2001-03-16 16:54 UTC
From: jiri dot kaderavek at webstep dot net Assigned:
Status: Closed Package: MySQL related
PHP Version: 4.0.4pl1 OS: Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: jiri dot kaderavek at webstep dot net
New email:
PHP Version: OS:

 

 [2001-01-27 12:46 UTC] jiri dot kaderavek at webstep dot net
Parameter $host is modified in function php_mysql_do_connect(). Example:

$host = "localhost:/tmp/mysql.sock";
$conn = mysql_connect($host .....
echo $host;

Output is: localhost/tmp/mysql.sock 
because of replacing of ":" charcter by null char in
this part of php_mysql_do_connect

===================

static void php_mysql_do_connect(INTERNAL_FUNCTION_PARAMETERS,int persistent)
{                                       
        char *user,*passwd,*host,*socket=NULL,*tmp;
        char *hashed_details;
        int hashed_details_length,port = MYSQL_PORT;
....
        /* We cannot use mysql_port anymore in windows, need to use
         * mysql_real_connect() to set the port.
         */

         if (host && (tmp=strchr(host,':'))) {
                *tmp=0;
                tmp++;
                if (tmp[0] != '/') {
                        port = atoi(tmp);
                } else {
                        socket = tmp;
                }
.....
}

===================


solution:
copying of *host content through *host2 pointer

===================


static void php_mysql_do_connect(INTERNAL_FUNCTION_PARAMETERS,int persistent)
{                                       
        char *user,*passwd,*host,*socket=NULL,*tmp,*host2;
        char *hashed_details;
        int hashed_details_length,port = MYSQL_PORT;
....
        /* We cannot use mysql_port anymore in windows, need to use
         * mysql_real_connect() to set the port.
         */
        
host2 = (char *) emalloc(strlen(SAFE_STRING(host) + 1));
        strcpy(host2, host);
        host = host2;

         if (host && (tmp=strchr(host,':'))) {
                *tmp=0;
                tmp++;
                if (tmp[0] != '/') {
                        port = atoi(tmp);
                } else {
                        socket = tmp;
                }
...
}

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-01-27 21:34 UTC] sniper@php.net
Could you please try the latest snapshot from http://snaps.php.net/
to check if this is fixed already?

--Jani
 [2001-03-16 16:54 UTC] sniper@php.net
No feedback, works for me just fine.

--Jani

 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue May 06 15:01:30 2025 UTC