tony2001 Fri Oct 20 23:21:06 2006 UTC Modified files: /php-src/ext/openssl openssl.c Log: fix #39217 (serialNumber is might be -1 when the value is too big) http://cvs.php.net/viewvc.cgi/php-src/ext/openssl/openssl.c?r1=1.128&r2=1.129&diff_format=u Index: php-src/ext/openssl/openssl.c diff -u php-src/ext/openssl/openssl.c:1.128 php-src/ext/openssl/openssl.c:1.129 --- php-src/ext/openssl/openssl.c:1.128 Sun Oct 15 21:10:09 2006 +++ php-src/ext/openssl/openssl.c Fri Oct 20 23:21:06 2006 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: openssl.c,v 1.128 2006/10/15 21:10:09 tony2001 Exp $ */ +/* $Id: openssl.c,v 1.129 2006/10/20 23:21:06 tony2001 Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -367,6 +367,40 @@ } /* }}} */ +static void php_asn1_integer_to_string(ASN1_INTEGER *a, char **str, int *str_len TSRMLS_DC) /* {{{ */ +{ + int i; + static const char *h="0123456789ABCDEF"; + zend_bool negative = 0; + + *str = NULL; + *str_len = 0; + + if (a == NULL) { + return; + } + + if (a->type & V_ASN1_NEG) { + negative = 1; + } + + if (a->length == 0) { + *str_len = spprintf(str, 0, "%s00", negative ? "-" : ""); + } else { + *str_len = a->length*2 + negative; + *str = emalloc(*str_len + 1); + if (negative) { + (*str)[0] = '-'; + } + for (i=0; i<a->length; i++) { + (*str)[i*2 + negative]=h[((unsigned char)a->data[i]>>4)&0x0f]; + (*str)[i*2 + negative + 1]=h[((unsigned char)a->data[i])&0x0f]; + } + (*str)[a->length*2 + negative] = '\0'; + } +} +/* }}} */ + static inline int php_openssl_config_check_syntax( const char * section_label, const char * config_filename, @@ -964,6 +998,8 @@ X509_EXTENSION *extension; ASN1_OCTET_STRING *extdata; char *extname; + char *serial; + int serial_len; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Z|b", &zcert, &useshortnames) == FAILURE) { return; @@ -989,7 +1025,9 @@ add_assoc_name_entry(return_value, "issuer", X509_get_issuer_name(cert), useshortnames TSRMLS_CC); add_assoc_long(return_value, "version", X509_get_version(cert)); - add_assoc_long(return_value, "serialNumber", ASN1_INTEGER_get(X509_get_serialNumber(cert))); + + php_asn1_integer_to_string(X509_get_serialNumber(cert), &serial, &serial_len TSRMLS_CC); + add_assoc_stringl(return_value, "serialNumber", serial, serial_len, 0); add_assoc_asn1_string(return_value, "validFrom", X509_get_notBefore(cert)); add_assoc_asn1_string(return_value, "validTo", X509_get_notAfter(cert));
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php