Skip to content

Commit 01d598a

Browse files
committed
Fix memory leaks in php_array_to_X509_sk() when push fails
1 parent 4b9e80e commit 01d598a

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

ext/openssl/openssl.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2581,7 +2581,10 @@ static STACK_OF(X509) *php_array_to_X509_sk(zval * zcerts, uint32_t arg_num, con
25812581
}
25822582

25832583
}
2584-
sk_X509_push(sk, cert);
2584+
if (sk_X509_push(sk, cert) <= 0) {
2585+
X509_free(cert);
2586+
goto push_fail_exit;
2587+
}
25852588
} ZEND_HASH_FOREACH_END();
25862589
} else {
25872590
/* a single certificate */
@@ -2599,11 +2602,20 @@ static STACK_OF(X509) *php_array_to_X509_sk(zval * zcerts, uint32_t arg_num, con
25992602
goto clean_exit;
26002603
}
26012604
}
2602-
sk_X509_push(sk, cert);
2605+
if (sk_X509_push(sk, cert) <= 0) {
2606+
X509_free(cert);
2607+
goto push_fail_exit;
2608+
}
26032609
}
26042610

26052611
clean_exit:
26062612
return sk;
2613+
2614+
push_fail_exit:
2615+
php_openssl_store_errors();
2616+
php_sk_X509_free(sk);
2617+
sk = NULL;
2618+
goto clean_exit;
26072619
}
26082620
/* }}} */
26092621

0 commit comments

Comments
 (0)