scottmac Mon Dec 8 11:53:30 2008 UTC Modified files: /php-src/ext/openssl xp_ssl.c Log: 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.40&r2=1.41&diff_format=u Index: php-src/ext/openssl/xp_ssl.c diff -u php-src/ext/openssl/xp_ssl.c:1.40 php-src/ext/openssl/xp_ssl.c:1.41 --- php-src/ext/openssl/xp_ssl.c:1.40 Sun Nov 16 23:03:59 2008 +++ php-src/ext/openssl/xp_ssl.c Mon Dec 8 11:53:30 2008 @@ -16,11 +16,12 @@ +----------------------------------------------------------------------+ */ -/* $Id: xp_ssl.c,v 1.40 2008/11/16 23:03:59 pajoye Exp $ */ +/* $Id: xp_ssl.c,v 1.41 2008/12/08 11:53:30 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); } }
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php