com php-src: Improved a bit error handling to avoid passing commands with incomplete controls: ext/ldap/ldap.c
| From: | Côme Bernigaud | Date: | Thu, 21 Sep 2017 08:05:41 +0000 |
| Subject: | com php-src: Improved a bit error handling to avoid passing commands with incomplete controls: ext/ldap/ldap.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-99493@lists.php.net to get a copy of this message | ||
Commit: 9275e05d8efc8672073adba472ef528be6708130
Author: Côme Chilliet <mcmic@php.net> Mon, 11 Sep 2017 11:46:47 +0200
Parents: 3a1ba93066c5c136a962152b2c37da5c61659be4
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=9275e05d8efc8672073adba472ef528be6708130
Log:
Improved a bit error handling to avoid passing commands with incomplete controls
Changed paths:
M ext/ldap/ldap.c
Diff:
diff --git a/ext/ldap/ldap.c b/ext/ldap/ldap.c
index 776475a..612b29d 100644
--- a/ext/ldap/ldap.c
+++ b/ext/ldap/ldap.c
@@ -217,7 +217,10 @@ static int _php_ldap_control_from_array(LDAP *ld, LDAPControl** ctrl, zval*
arra
if (Z_TYPE_P(val) != IS_ARRAY) {
convert_to_string_ex(val);
control_value = ber_memalloc(sizeof * control_value);
- if (control_value != NULL) {
+ if (control_value == NULL) {
+ rc = -1;
+ php_error_docref(NULL, E_WARNING, "Failed to allocate control value");
+ } else {
control_value->bv_val = Z_STRVAL_P(val);
control_value->bv_len = Z_STRLEN_P(val);
}
@@ -238,21 +241,29 @@ static int _php_ldap_control_from_array(LDAP *ld, LDAPControl** ctrl, zval*
arra
}
}
control_value = ber_memalloc(sizeof * control_value);
- if (control_value != NULL) {
+ if (control_value == NULL) {
+ rc = -1;
+ php_error_docref(NULL, E_WARNING, "Failed to allocate control value");
+ } else {
rc = ldap_create_page_control_value(ld, pagesize, cookie, control_value);
if (rc != LDAP_SUCCESS) {
php_error_docref(NULL, E_WARNING, "Failed to create paged result control value: %s
(%d)", ldap_err2string(rc), rc);
- control_value = NULL;
}
}
} else if (strcmp(control_oid, LDAP_CONTROL_ASSERT) == 0) {
zval* tmp;
char* assert;
- if ((tmp = zend_hash_str_find(Z_ARRVAL_P(val), "filter", sizeof("filter") -
1)) != NULL) {
+ if ((tmp = zend_hash_str_find(Z_ARRVAL_P(val), "filter", sizeof("filter") -
1)) == NULL) {
+ rc = -1;
+ php_error_docref(NULL, E_WARNING, "Filter missing from assert control value array");
+ } else {
convert_to_string_ex(tmp);
assert = Z_STRVAL_P(tmp);
control_value = ber_memalloc(sizeof * control_value);
- if (control_value != NULL) {
+ if (control_value == NULL) {
+ rc = -1;
+ php_error_docref(NULL, E_WARNING, "Failed to allocate control value");
+ } else {
// ldap_create_assertion_control_value does not reset ld_errno, we need to do it ourselves
// See http://www.openldap.org/its/index.cgi/Incoming?id=8674
int success = LDAP_SUCCESS;
@@ -260,7 +271,6 @@ static int _php_ldap_control_from_array(LDAP *ld, LDAPControl** ctrl, zval* arra
rc = ldap_create_assertion_control_value(ld, assert, control_value);
if (rc != LDAP_SUCCESS) {
php_error_docref(NULL, E_WARNING, "Failed to create assert control value: %s (%d)",
ldap_err2string(rc), rc);
- control_value = NULL;
}
}
}