cvs: php4 /ext/sockets sockets.c
| From: | Stanislav Malyshev | Date: | Tue, 12 Dec 2000 16:56:35 +0000 |
| Subject: | cvs: php4 /ext/sockets sockets.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-3095@lists.php.net to get a copy of this message | ||
stas Tue Dec 12 08:56:35 2000 EDT
Modified files:
/php4/ext/sockets sockets.c
Log:
Fix socket read returning bad values.
Index: php4/ext/sockets/sockets.c
diff -u php4/ext/sockets/sockets.c:1.24 php4/ext/sockets/sockets.c:1.25
--- php4/ext/sockets/sockets.c:1.24 Sun Dec 3 11:17:09 2000
+++ php4/ext/sockets/sockets.c Tue Dec 12 08:56:34 2000
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: sockets.c,v 1.24 2000/12/03 19:17:09 sterling Exp $ */
+/* $Id: sockets.c,v 1.25 2000/12/12 16:56:34 stas Exp $ */
#include "php.h"
@@ -683,7 +683,7 @@
read_function = (int (*)(int, void *, int)) php_read;
}
- tmpbuf = emalloc(Z_LVAL_PP(length)*sizeof(char));
+ tmpbuf = emalloc((Z_LVAL_PP(length)+1)*sizeof(char));
if (tmpbuf == NULL) {
php_error(E_WARNING, "Couldn't allocate memory from %s()",
get_active_function_name());
RETURN_FALSE;
@@ -692,19 +692,9 @@
ret = (*read_function)(Z_LVAL_PP(fd), tmpbuf, Z_LVAL_PP(length));
if (ret >= 0) {
- if (Z_STRLEN_PP(buf) > 0) {
- efree(Z_STRVAL_PP(buf));
- }
- if (ZEND_NUM_ARGS() == 4 && Z_LVAL_PP(binary) != PHP_NORMAL_READ) {
- Z_STRVAL_PP(buf) = emalloc(ret);
- memcpy(Z_STRVAL_PP(buf), tmpbuf, ret);
- Z_STRLEN_PP(buf) = ret;
- } else {
- Z_STRVAL_PP(buf) = estrndup(tmpbuf,strlen(tmpbuf));
- Z_STRLEN_PP(buf) = strlen(tmpbuf);
- ret = strlen(tmpbuf);
- }
- efree(tmpbuf);
+ tmpbuf[ret] = '\0';
+ Z_STRVAL_PP(buf) = erealloc(tmpbuf, ret+1);
+ Z_STRLEN_PP(buf) = ret;
RETURN_LONG(ret);
} else {