cvs: php4 /ext/standard fsock.c /main network.c php_network.h

From: Date: Sun, 17 Mar 2002 13:19:27 +0000
Subject: cvs: php4 /ext/standard fsock.c /main network.c php_network.h
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-10287@lists.php.net to get a copy of this message
wez Sun Mar 17 08:19:27 2002 EDT Modified files: /php4/ext/standard fsock.c /php4/main network.c php_network.h Log: Fix for Bug #16121: make unix socket names binary safe. # Could be applied to 4.2 branch, but I don't have a working copy, and # I don't think it's amazingly critical. Index: php4/ext/standard/fsock.c diff -u php4/ext/standard/fsock.c:1.90 php4/ext/standard/fsock.c:1.91 --- php4/ext/standard/fsock.c:1.90 Sat Mar 16 20:58:41 2002 +++ php4/ext/standard/fsock.c Sun Mar 17 08:19:23 2002 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: fsock.c,v 1.90 2002/03/17 01:58:41 wez Exp $ */ +/* $Id: fsock.c,v 1.91 2002/03/17 13:19:23 wez Exp $ */ /* converted to PHP Streams and moved much code to main/network.c [wez] */ @@ -219,7 +219,7 @@ #endif } else - stream = php_stream_sock_open_unix(host, persistent, &tv); + stream = php_stream_sock_open_unix(host, host_len, persistent, &tv); if (stream && persistent) { zend_hash_update(&FG(ht_persistent_socks), hashkey, strlen(hashkey) + 1, Index: php4/main/network.c diff -u php4/main/network.c:1.36 php4/main/network.c:1.37 --- php4/main/network.c:1.36 Sat Mar 16 09:39:51 2002 +++ php4/main/network.c Sun Mar 17 08:19:27 2002 @@ -15,7 +15,7 @@ | Author: Stig Venaas <venaas@uninett.no> | +----------------------------------------------------------------------+ */ -/* $Id: network.c,v 1.36 2002/03/16 14:39:51 wez Exp $ */ +/* $Id: network.c,v 1.37 2002/03/17 13:19:27 wez Exp $ */ #define PHP_SOCK_CHUNK_SIZE 8192 #define MAX_CHUNKS_PER_READ 10 @@ -447,7 +447,7 @@ return php_stream_sock_open_from_socket(socket, persistent); } -PHPAPI php_stream *php_stream_sock_open_unix(const char *path, int persistent, struct timeval *timeout) +PHPAPI php_stream *php_stream_sock_open_unix(const char *path, int pathlen, int persistent, struct timeval *timeout) { #if defined(AF_UNIX) int socketd; @@ -459,7 +459,19 @@ memset(&unix_addr, 0, sizeof(unix_addr)); unix_addr.sun_family = AF_UNIX; - strlcpy(unix_addr.sun_path, path, sizeof(unix_addr.sun_path)); + + /* we need to be binary safe for the on systems that support an abstract + * namespace */ + if (pathlen >= sizeof(unix_addr.sun_path)) { + /* On linux, when the path begins with a NUL byte we are + * referring to an abstract namespace. In theory we should + * allow an extra byte below, since we don't need the NULL. + * BUT, to get into this branch of code, the name is too long, + * so we don't care. */ + pathlen = sizeof(unix_addr.sun_path) - 1; + } + + memcpy(unix_addr.sun_path, path, pathlen); if (php_connect_nonb(socketd, (struct sockaddr *) &unix_addr, sizeof(unix_addr), timeout) == SOCK_CONN_ERR) return NULL; Index: php4/main/php_network.h diff -u php4/main/php_network.h:1.15 php4/main/php_network.h:1.16 --- php4/main/php_network.h:1.15 Fri Mar 15 21:33:00 2002 +++ php4/main/php_network.h Sun Mar 17 08:19:27 2002 @@ -15,7 +15,7 @@ | Author: Stig Venaas <venaas@uninett.no> | +----------------------------------------------------------------------+ */ -/* $Id: php_network.h,v 1.15 2002/03/16 02:33:00 wez Exp $ */ +/* $Id: php_network.h,v 1.16 2002/03/17 13:19:27 wez Exp $ */ #ifndef _PHP_NETWORK_H #define _PHP_NETWORK_H @@ -106,7 +106,7 @@ /* open a connection to a host using php_hostconnect and return a stream */ PHPAPI php_stream *php_stream_sock_open_host(const char *host, unsigned short port, int socktype, int timeout, int persistent); -PHPAPI php_stream *php_stream_sock_open_unix(const char *path, int persistent, struct timeval *timeout); +PHPAPI php_stream *php_stream_sock_open_unix(const char *path, int pathlen, int persistent, struct timeval *timeout); PHPAPI void php_stream_sock_set_timeout(php_stream *stream, struct timeval *timeout); PHPAPI int php_stream_sock_set_blocking(php_stream *stream, int mode);

« previous php.cvs (#10287) next »