Skip to content

Commit 955bc1d

Browse files
committed
Using SUCCESS and FAILURE for return values
Using zend_bool for boolean arguments and return values Reduced one level of zval indirection where possible
1 parent e45eacd commit 955bc1d

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

ext/openssl/openssl.c

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1672,18 +1672,18 @@ PHP_FUNCTION(openssl_x509_export)
16721672
}
16731673
/* }}} */
16741674

1675-
static int php_openssl_x509_fingerprint(X509 *peer, const char *method, int raw, char **out, int *out_len)
1675+
static int php_openssl_x509_fingerprint(X509 *peer, const char *method, zend_bool raw, char **out, int *out_len)
16761676
{
16771677
unsigned char md[EVP_MAX_MD_SIZE];
16781678
const EVP_MD *mdtype;
16791679
int n;
16801680

16811681
if (!(mdtype = EVP_get_digestbyname(method))) {
1682-
php_error_docref(NULL TSRMLS_CC, E_WARNING, "`%s`: Unknown signature algorithm", method);
1683-
return 0;
1682+
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unknown signature algorithm");
1683+
return FAILURE;
16841684
} else if (!X509_digest(peer, mdtype, md, &n)) {
16851685
php_error_docref(NULL TSRMLS_CC, E_ERROR, "Could not generate signature");
1686-
return 0;
1686+
return FAILURE;
16871687
}
16881688

16891689
if (raw) {
@@ -1696,7 +1696,7 @@ static int php_openssl_x509_fingerprint(X509 *peer, const char *method, int raw,
16961696
make_digest_ex(*out, md, n);
16971697
}
16981698

1699-
return 1;
1699+
return SUCCESS;
17001700
}
17011701

17021702
static int php_x509_fingerprint_cmp(X509 *peer, const char *method, const char *expected)
@@ -1705,20 +1705,20 @@ static int php_x509_fingerprint_cmp(X509 *peer, const char *method, const char *
17051705
int fingerprint_len;
17061706
int result = -1;
17071707

1708-
if (php_openssl_x509_fingerprint(peer, method, 0, &fingerprint, &fingerprint_len)) {
1708+
if (php_openssl_x509_fingerprint(peer, method, 0, &fingerprint, &fingerprint_len) == SUCCESS) {
17091709
result = strcmp(expected, fingerprint);
17101710
efree(fingerprint);
17111711
}
17121712

17131713
return result;
17141714
}
17151715

1716-
static int php_x509_fingerprint_match(X509 *peer, zval **val)
1716+
static zend_bool php_x509_fingerprint_match(X509 *peer, zval *val)
17171717
{
1718-
if (Z_TYPE_PP(val) == IS_STRING) {
1718+
if (Z_TYPE_P(val) == IS_STRING) {
17191719
const char *method = NULL;
17201720

1721-
switch (Z_STRLEN_PP(val)) {
1721+
switch (Z_STRLEN_P(val)) {
17221722
case 32:
17231723
method = "md5";
17241724
break;
@@ -1728,19 +1728,19 @@ static int php_x509_fingerprint_match(X509 *peer, zval **val)
17281728
break;
17291729
}
17301730

1731-
return method && php_x509_fingerprint_cmp(peer, method, Z_STRVAL_PP(val)) == 0;
1732-
} else if (Z_TYPE_PP(val) == IS_ARRAY) {
1731+
return method && php_x509_fingerprint_cmp(peer, method, Z_STRVAL_P(val)) == 0;
1732+
} else if (Z_TYPE_P(val) == IS_ARRAY) {
17331733
HashPosition pos;
17341734
zval **current;
17351735
char *key;
17361736
uint key_len;
17371737
ulong key_index;
17381738

1739-
for (zend_hash_internal_pointer_reset_ex(Z_ARRVAL_PP(val), &pos);
1740-
zend_hash_get_current_data_ex(Z_ARRVAL_PP(val), (void **)&current, &pos) == SUCCESS;
1741-
zend_hash_move_forward_ex(Z_ARRVAL_PP(val), &pos)
1739+
for (zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(val), &pos);
1740+
zend_hash_get_current_data_ex(Z_ARRVAL_P(val), (void **)&current, &pos) == SUCCESS;
1741+
zend_hash_move_forward_ex(Z_ARRVAL_P(val), &pos)
17421742
) {
1743-
int key_type = zend_hash_get_current_key_ex(Z_ARRVAL_PP(val), &key, &key_len, &key_index, 0, &pos);
1743+
int key_type = zend_hash_get_current_key_ex(Z_ARRVAL_P(val), &key, &key_len, &key_index, 0, &pos);
17441744

17451745
if (key_type == HASH_KEY_IS_STRING
17461746
&& Z_TYPE_PP(current) == IS_STRING
@@ -1776,7 +1776,7 @@ PHP_FUNCTION(openssl_x509_fingerprint)
17761776
RETURN_FALSE;
17771777
}
17781778

1779-
if (php_openssl_x509_fingerprint(cert, method, raw_output, &fingerprint, &fingerprint_len)) {
1779+
if (php_openssl_x509_fingerprint(cert, method, raw_output, &fingerprint, &fingerprint_len) == SUCCESS) {
17801780
RETVAL_STRINGL(fingerprint, fingerprint_len, 0);
17811781
} else {
17821782
RETVAL_FALSE;
@@ -4989,7 +4989,7 @@ int php_openssl_apply_verification_policy(SSL *ssl, X509 *peer, php_stream *stre
49894989

49904990
if (GET_VER_OPT("peer_fingerprint")) {
49914991
if (Z_TYPE_PP(val) == IS_STRING || Z_TYPE_PP(val) == IS_ARRAY) {
4992-
if (!php_x509_fingerprint_match(peer, val)) {
4992+
if (!php_x509_fingerprint_match(peer, *val)) {
49934993
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Peer fingerprint doesn't match");
49944994
return FAILURE;
49954995
}

0 commit comments

Comments
 (0)