Skip to content

Commit

Permalink
Prevent leaking x509 and csr resources if it is not requested
Browse files Browse the repository at this point in the history
All functions using php_openssl_x509_from_zval or php_openssl_csr_from_zval
with makeresource equal to 0 do not deref the resource which means there
is a leak till the end of the request. This can cause issues for long
running apps. It is a generic solution for bug #75363 which also covers
other functions.
  • Loading branch information
bukka committed Oct 30, 2017
1 parent d8ccffa commit fc169d2
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions ext/openssl/openssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1587,10 +1587,11 @@ static X509 * php_openssl_x509_from_zval(zval * val, int makeresource, zend_reso
if (!what) {
return NULL;
}
/* this is so callers can decide if they should free the X509 */
if (resourceval) {
*resourceval = res;
Z_ADDREF_P(val);
if (makeresource) {
Z_ADDREF_P(val);
}
}
return (X509*)what;
}
Expand Down Expand Up @@ -3047,7 +3048,9 @@ static X509_REQ * php_openssl_csr_from_zval(zval * val, int makeresource, zend_r
if (what) {
if (resourceval) {
*resourceval = res;
Z_ADDREF_P(val);
if (makeresource) {
Z_ADDREF_P(val);
}
}
return (X509_REQ*)what;
}
Expand Down

0 comments on commit fc169d2

Please sign in to comment.