php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #2825 Unix Socket Ignored in mysql_connect()
Submitted: 1999-11-24 21:06 UTC Modified: 2000-03-20 02:41 UTC
From: jadiel at thevision dot net Assigned:
Status: Closed Package: MySQL related
PHP Version: 3.0.12 OS: Linux 2.0.xx
Private report: No CVE-ID: None
 [1999-11-24 21:06 UTC] jadiel at thevision dot net
I've attached a small patch to this message, apply it to mysql.c in the functions directory for PHP 3.0.12.  Simple fix, you could probably hand apply it to 3.0.10 and 3.0.11.  It really isn't a bug, it is a logic error.

The bug in PHP 3.0.12 incorrectly ignores the socket value when specified with the port number.  This prevents things like accessing multiple MySQL servers on a host that supports multiple MySQL servers.  This can cause major problems for the unaware.  That is, you could corrupt your MySQL database.

In my case, I have 5 MySQL servers running on the same host.  Each has a different port and different unix socket.  I can specify the port, PHP will connect but will use the default socket even when I specify the socket also.

Additionally, I scanned the Zend source and it appears that Zend doesn't even address the socket issue, it specifies the default socket in all mysql_connect calls, this can also pose a serious problem if more than one MySQL server is running on the same host, corrupted database galore.  My question about Zend is does it handle setting the unix socket for MySQL connections differently, otherwise this is a serious error that should be addressed.  I can't seem to find any documentation on Zend, I'm assuming that mysql_connect() is expected to have same functionality as PHP 3.0.12.

Thanks,
Jose

Diff File:

*** php-3.0.12/functions/mysql.c	Sun Jul  4 10:30:42 1999
--- php-3.0.12.socketfixed/functions/mysql.c	Wed Nov 24 10:07:55 1999
***************
*** 386,392 ****
  #if APACHE
  	void (*handler) (int);
  #endif
! 	char *user,*passwd,*host,*socket = NULL,*tmp;
  	char *hashed_details;
  	int hashed_details_length,port = 0;
  	MYSQL *mysql;
--- 386,392 ----
  #if APACHE
  	void (*handler) (int);
  #endif
! 	char *user,*passwd,*host,*socket = NULL,*tmp,*tmp2;
  	char *hashed_details;
  	int hashed_details_length,port = 0;
  	MYSQL *mysql;
***************
*** 466,471 ****
--- 466,476 ----
  		tmp++;
  		if (tmp[0] != '/') {
  			port = atoi(tmp);
+ 			if (tmp2=strchr(tmp,':')) {
+ 				*tmp2=0 ;
+ 				tmp2++ ;
+ 				socket = tmp2 ;
+ 			}
  		} else {
  			socket = tmp;
  		}


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2000-03-20 02:41 UTC] rasmus at cvs dot php dot net
Please note that there is no MySQL support in Zend.  You are talking about PHP 4 in this message.
And your suggestion regarding needing to be able to specify both the port and the socket in a mysql_connect() is a good one and has been committed to current cvs in both php 3 and 4
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri May 17 11:01:34 2024 UTC