Skip to content

Commit 7d5c9f2

Browse files
committed
openssl: Use proper error propagation when X509_dup() fails in openssl_x509_read()
Otherwise x509 field is NULL and can cause a NULL deref which is UB (and causes a SEGV).
1 parent 6e87107 commit 7d5c9f2

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

ext/openssl/openssl.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2517,9 +2517,20 @@ PHP_FUNCTION(openssl_x509_read)
25172517
RETURN_FALSE;
25182518
}
25192519

2520+
X509 *obj_x509;
2521+
if (cert_obj) {
2522+
obj_x509 = X509_dup(cert);
2523+
if (!obj_x509) {
2524+
php_error_docref(NULL, E_WARNING, "X.509 Certificate could not be duplicated");
2525+
RETURN_FALSE;
2526+
}
2527+
} else {
2528+
obj_x509 = cert;
2529+
}
2530+
25202531
object_init_ex(return_value, php_openssl_certificate_ce);
25212532
x509_cert_obj = Z_OPENSSL_CERTIFICATE_P(return_value);
2522-
x509_cert_obj->x509 = cert_obj ? X509_dup(cert) : cert;
2533+
x509_cert_obj->x509 = obj_x509;
25232534
}
25242535
/* }}} */
25252536

0 commit comments

Comments
 (0)