php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #33663 The -b parameter to the FastCGI binary does not accept pathnames
Submitted: 2005-07-12 16:16 UTC Modified: 2005-07-12 18:20 UTC
From: bengen+php at hilluzination dot de Assigned:
Status: Not a bug Package: CGI/CLI related
PHP Version: 4.3.11 OS: GNU/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: bengen+php at hilluzination dot de
New email:
PHP Version: OS:

 

 [2005-07-12 16:16 UTC] bengen+php at hilluzination dot de
Description:
------------
I would like to start an instance of the FastCGI interpreter which listens to a Unix Domain socket. libfcgi would this, but the wrapper code in cgi_main.c differentiates only between

php4-cgi -b $ADDRESS:$PORT

and

php4-cgi -b [:]$PORT

If the colon is missing, it is assumed that the user wants a TCP socket which is not bound to a specific address and thus a colon is prepended. This breaks passing a path to a Unix Domain socket.
Fix: Since libfcgi apparently accepts the port only in numeric form anyhow, I have simply added a check whether the first character of the argument is a digit. In this case, it is assumed to be a port and prepended with a colon. If not, it is assumed to be a pathname.
Alternatively, one could altogether remove the code which prepends the colon and document the behavior.

diff -ui cgi_main.c.orig cgi_main.c
--- cgi_main.c.orig	2005-07-12 15:04:19.000000000 +0200
+++ cgi_main.c	2005-07-12 15:53:48.000000000 +0200
@@ -1140,12 +1140,12 @@
 		/* this must be done to make FCGX_OpenSocket work correctly 
 		   bug 23664 */
 		close(0);
-		/* Pass on the arg to the FastCGI library, with one exception.
-		 * If just a port is specified, then we prepend a ':' onto the
-		 * path (it's what the fastcgi library expects)
+		/* Pass on the arg to the FastCGI library, with one exception. 
+		 * If just a numeric port is specified, then we prepend a ':'
+		 * onto the path (it's what the fastcgi library expects)
 		 */
 		
-		if (strchr(bindpath, ':') == NULL) {
+		if ( isdigit(bindpath[0]) && (strchr(bindpath, ':') == NULL) ) {
 			char *tmp;
 
 			tmp = malloc(strlen(bindpath) + 2);


Actual result:
--------------
bengen@ataraxia:~$ php4-cgi -b /tmp/foo
bind/listen: No such file or directory
Couldn't create FastCGI listen socket on port /tmp/foo
bengen@ataraxia:~$ echo $?
255
bengen@ataraxia:~$ 

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-07-12 16:17 UTC] bengen+php at hilluzination dot de
Um. "not" added to title.
 [2005-07-12 18:05 UTC] sniper@php.net
Please do not submit the same bug more than once. An existing
bug report already describes this very problem. Even if you feel
that your issue is somewhat different, the resolution is likely
to be the same. 

Thank you for your interest in PHP.

See bug #29574
 [2005-07-12 18:20 UTC] bengen+php at hilluzination dot de
Sorry about the duplicate bug. For some reason I had not found the other bug report even though I looked.

The solution attached to #29574 looks similar, but it is wrong: If the user wants a socket foo created in the working directory, he would just say php4-cgi -b foo, but the php interpreter would still prepend a colon.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 04:01:29 2024 UTC