File php-5.2.x-CVE-2009-3291.patch of Package php5

Index: ext/openssl/openssl.c
===================================================================
--- ext/openssl/openssl.c	(revisión: 288328)
+++ ext/openssl/openssl.c	(revisión: 288329)
@@ -3845,8 +3845,15 @@
 	GET_VER_OPT_STRING("CN_match", cnmatch);
 	if (cnmatch) {
 		int match = 0;
+		int name_len = X509_NAME_get_text_by_NID(name, NID_commonName, buf, sizeof(buf));
 
-		X509_NAME_get_text_by_NID(name, NID_commonName, buf, sizeof(buf));
+		if (name_len == -1) {
+			php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to locate peer certificate CN");
+			return FAILURE;
+		} else if (name_len != strlen(buf)) {
+			php_error_docref(NULL TSRMLS_CC, E_WARNING, "Peer certificate CN=`%.*s' is malformed", name_len, buf);
+			return FAILURE;
+		}
 
 		match = strcmp(cnmatch, buf) == 0;
 		if (!match && strlen(buf) > 3 && buf[0] == '*' && buf[1] == '.') {
@@ -3861,10 +3868,7 @@
 
 		if (!match) {
 			/* didn't match */
-			php_error_docref(NULL TSRMLS_CC, E_WARNING,
-					"Peer certificate CN=`%s' did not match expected CN=`%s'",
-					buf, cnmatch);
-
+			php_error_docref(NULL TSRMLS_CC, E_WARNING, "Peer certificate CN=`%.*s' did not match expected CN=`%s'", name_len, buf, cnmatch);
 			return FAILURE;
 		}
 	}
openSUSE Build Service is sponsored by