cvs: php-src(PHP_5_3) /ext/openssl xp_ssl.c

From: Date: Mon, 08 Dec 2008 11:54:22 +0000
Subject: cvs: php-src(PHP_5_3) /ext/openssl xp_ssl.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-54755@lists.php.net to get a copy of this message
scottmac Mon Dec 8 11:54:22 2008 UTC Modified files: (Branch: PHP_5_3) /php-src/ext/openssl xp_ssl.c Log: MFH Fix bug #46748, segfault when SSL has more than one error message. http://cvs.php.net/viewvc.cgi/php-src/ext/openssl/xp_ssl.c?r1=1.22.2.3.2.9.2.8&r2=1.22.2.3.2.9.2.9&diff_format=u Index: php-src/ext/openssl/xp_ssl.c diff -u php-src/ext/openssl/xp_ssl.c:1.22.2.3.2.9.2.8 php-src/ext/openssl/xp_ssl.c:1.22.2.3.2.9.2.9 --- php-src/ext/openssl/xp_ssl.c:1.22.2.3.2.9.2.8 Sun Nov 16 23:14:12 2008 +++ php-src/ext/openssl/xp_ssl.c Mon Dec 8 11:54:22 2008 @@ -16,11 +16,12 @@ +----------------------------------------------------------------------+ */ -/* $Id: xp_ssl.c,v 1.22.2.3.2.9.2.8 2008/11/16 23:14:12 pajoye Exp $ */ +/* $Id: xp_ssl.c,v 1.22.2.3.2.9.2.9 2008/12/08 11:54:22 scottmac Exp $ */ #include "php.h" #include "ext/standard/file.h" #include "streams/php_streams_int.h" +#include "ext/standard/php_smart_str.h" #include "php_network.h" #include "php_openssl.h" #include <openssl/ssl.h> @@ -89,9 +90,8 @@ php_openssl_netstream_data_t *sslsock = (php_openssl_netstream_data_t*)stream->abstract; int err = SSL_get_error(sslsock->ssl_handle, nr_bytes); char esbuf[512]; - char *ebuf = NULL, *wptr = NULL; - size_t ebuf_size = 0; - unsigned long code, ecode; + smart_str ebuf = {0}; + unsigned long ecode; int retry = 1; switch(err) { @@ -142,35 +142,23 @@ default: do { - /* allow room for a NUL and an optional \n */ - if (ebuf) { - esbuf[0] = '\n'; - esbuf[1] = '\0'; - ERR_error_string_n(ecode, esbuf + 1, sizeof(esbuf) - 2); - } else { - esbuf[0] = '\0'; - ERR_error_string_n(ecode, esbuf, sizeof(esbuf) - 1); + // NULL is automatically added + ERR_error_string_n(ecode, esbuf, sizeof(esbuf)); + if (ebuf.c) { + smart_str_appendc(&ebuf, '\n'); } - code = strlen(esbuf); - esbuf[code] = '\0'; - - ebuf = erealloc(ebuf, ebuf_size + code + 1); - if (wptr == NULL) { - wptr = ebuf; - } - - /* also copies the NUL */ - memcpy(wptr, esbuf, code + 1); - wptr += code; + smart_str_appends(&ebuf, esbuf); } while ((ecode = ERR_get_error()) != 0); + smart_str_0(&ebuf); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "SSL operation failed with code %d. %s%s", err, - ebuf ? "OpenSSL Error messages:\n" : "", - ebuf ? ebuf : ""); - if (ebuf) { - efree(ebuf); + ebuf.c ? "OpenSSL Error messages:\n" : "", + ebuf.c ? ebuf.c : ""); + if (ebuf.c) { + smart_str_free(&ebuf); } }

« previous php.cvs (#54755) next »