Skip to content

Commit 980ffff

Browse files
committed
ext/ldap: Refactor ldap_parse_exop() to not rely on argnum
1 parent 2b92e26 commit 980ffff

File tree

1 file changed

+24
-24
lines changed

1 file changed

+24
-24
lines changed

ext/ldap/ldap.c

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3278,14 +3278,14 @@ PHP_FUNCTION(ldap_parse_result)
32783278
/* {{{ Extract information from extended operation result */
32793279
PHP_FUNCTION(ldap_parse_exop)
32803280
{
3281-
zval *link, *result, *retdata, *retoid;
3281+
zval *link, *result, *retdata = NULL, *retoid = NULL;
32823282
ldap_linkdata *ld;
32833283
ldap_resultdata *ldap_result;
32843284
char *lretoid;
32853285
struct berval *lretdata;
3286-
int rc, myargcount = ZEND_NUM_ARGS();
3286+
int rc;
32873287

3288-
if (zend_parse_parameters(myargcount, "OO|zz", &link, ldap_link_ce, &result, ldap_result_ce, &retdata, &retoid) != SUCCESS) {
3288+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "OO|zz", &link, ldap_link_ce, &result, ldap_result_ce, &retdata, &retoid) != SUCCESS) {
32893289
RETURN_THROWS();
32903290
}
32913291

@@ -3296,34 +3296,34 @@ PHP_FUNCTION(ldap_parse_exop)
32963296
VERIFY_LDAP_RESULT_OPEN(ldap_result);
32973297

32983298
rc = ldap_parse_extended_result(ld->link, ldap_result->result,
3299-
myargcount > 3 ? &lretoid: NULL,
3300-
myargcount > 2 ? &lretdata: NULL,
3299+
retoid ? &lretoid: NULL,
3300+
retdata ? &lretdata: NULL,
33013301
0);
33023302
if (rc != LDAP_SUCCESS) {
33033303
php_error_docref(NULL, E_WARNING, "Unable to parse extended operation result: %s", ldap_err2string(rc));
33043304
RETURN_FALSE;
33053305
}
33063306

3307-
/* Reverse -> fall through */
3308-
switch (myargcount) {
3309-
case 4:
3310-
if (lretoid == NULL) {
3311-
ZEND_TRY_ASSIGN_REF_EMPTY_STRING(retoid);
3312-
} else {
3313-
ZEND_TRY_ASSIGN_REF_STRING(retoid, lretoid);
3314-
ldap_memfree(lretoid);
3315-
}
3316-
ZEND_FALLTHROUGH;
3317-
case 3:
3318-
/* use arg #3 as the data returned by the server */
3319-
if (lretdata == NULL) {
3320-
ZEND_TRY_ASSIGN_REF_EMPTY_STRING(retdata);
3321-
} else {
3322-
ZEND_TRY_ASSIGN_REF_STRINGL(retdata, lretdata->bv_val, lretdata->bv_len);
3323-
ldap_memfree(lretdata->bv_val);
3324-
ldap_memfree(lretdata);
3325-
}
3307+
if (retoid) {
3308+
if (lretoid == NULL) {
3309+
ZEND_TRY_ASSIGN_REF_EMPTY_STRING(retoid);
3310+
} else {
3311+
ZEND_TRY_ASSIGN_REF_STRING(retoid, lretoid);
3312+
ldap_memfree(lretoid);
3313+
}
33263314
}
3315+
3316+
if (retdata) {
3317+
/* use arg #3 as the data returned by the server */
3318+
if (lretdata == NULL) {
3319+
ZEND_TRY_ASSIGN_REF_EMPTY_STRING(retdata);
3320+
} else {
3321+
ZEND_TRY_ASSIGN_REF_STRINGL(retdata, lretdata->bv_val, lretdata->bv_len);
3322+
ldap_memfree(lretdata->bv_val);
3323+
ldap_memfree(lretdata);
3324+
}
3325+
}
3326+
33273327
RETURN_TRUE;
33283328
}
33293329
/* }}} */

0 commit comments

Comments
 (0)