From: Stanislav Malyshev Date: Tue, 12 Dec 2000 16:56:34 +0000 (+0000) Subject: Fix socket read returning bad values. X-Git-Tag: php-4.0.5RC1~923 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5dc97420714cbff873b491baa5876283ca260309;p=php Fix socket read returning bad values. --- diff --git a/ext/sockets/sockets.c b/ext/sockets/sockets.c index 43017c70bb..c9464d4620 100644 --- a/ext/sockets/sockets.c +++ b/ext/sockets/sockets.c @@ -683,7 +683,7 @@ PHP_FUNCTION(read) 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 @@ PHP_FUNCTION(read) 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 {