Skip to content

Commit 0676f39

Browse files
committed
Remove unnecessary resource checks in openssl ext
The resource val is already checking Z_TYPE_P(val) == IS_RESOURCE. There is no need to call extended resource fetch functions though.
1 parent c3bd8cd commit 0676f39

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

ext/openssl/openssl.c

+11-8
Original file line numberDiff line numberDiff line change
@@ -1351,14 +1351,15 @@ static X509 * php_openssl_x509_from_zval(zval * val, int makeresource, zend_reso
13511351
if (Z_TYPE_P(val) == IS_RESOURCE) {
13521352
/* is it an x509 resource ? */
13531353
void * what;
1354+
zend_resource *res = Z_RES_P(val);
13541355

1355-
what = zend_fetch_resource_ex(val, "OpenSSL X.509", le_x509);
1356+
what = zend_fetch_resource(res, "OpenSSL X.509", le_x509);
13561357
if (!what) {
13571358
return NULL;
13581359
}
13591360
/* this is so callers can decide if they should free the X509 */
13601361
if (resourceval) {
1361-
*resourceval = Z_RES_P(val);
1362+
*resourceval = res;
13621363
Z_ADDREF_P(val);
13631364
}
13641365
return (X509*)what;
@@ -2762,11 +2763,12 @@ static X509_REQ * php_openssl_csr_from_zval(zval * val, int makeresource, zend_r
27622763
}
27632764
if (Z_TYPE_P(val) == IS_RESOURCE) {
27642765
void * what;
2766+
zend_resource *res = Z_RES_P(val);
27652767

2766-
what = zend_fetch_resource_ex(val, "OpenSSL X.509 CSR", le_csr);
2768+
what = zend_fetch_resource(res, "OpenSSL X.509 CSR", le_csr);
27672769
if (what) {
27682770
if (resourceval) {
2769-
*resourceval = Z_RES_P(val);
2771+
*resourceval = res;
27702772
Z_ADDREF_P(val);
27712773
}
27722774
return (X509_REQ*)what;
@@ -3219,20 +3221,21 @@ static EVP_PKEY * php_openssl_evp_from_zval(zval * val, int public_key, char * p
32193221

32203222
if (Z_TYPE_P(val) == IS_RESOURCE) {
32213223
void * what;
3224+
zend_resource * res = Z_RES_P(val);
32223225

3223-
what = zend_fetch_resource2_ex(val, "OpenSSL X.509/key", le_x509, le_key);
3226+
what = zend_fetch_resource2(res, "OpenSSL X.509/key", le_x509, le_key);
32243227
if (!what) {
32253228
TMP_CLEAN;
32263229
}
32273230
if (resourceval) {
3228-
*resourceval = Z_RES_P(val);
3231+
*resourceval = res;
32293232
Z_ADDREF_P(val);
32303233
}
3231-
if (Z_RES_P(val)->type == le_x509) {
3234+
if (res->type == le_x509) {
32323235
/* extract key from cert, depending on public_key param */
32333236
cert = (X509*)what;
32343237
free_cert = 0;
3235-
} else if (Z_RES_P(val)->type == le_key) {
3238+
} else if (res->type == le_key) {
32363239
int is_priv;
32373240

32383241
is_priv = php_openssl_is_private_key((EVP_PKEY*)what);

0 commit comments

Comments
 (0)