Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor implementation of ldap_modify_batch() #16033

Merged
merged 14 commits into from
Sep 27, 2024

Conversation

Girgias
Copy link
Member

@Girgias Girgias commented Sep 24, 2024

Depends on #16032 getting fixed, as I found those issue while staring at the code and writing the tests.

Comment on lines +2538 to +2540
/* make sure the DN contains no NUL bytes */
if (zend_char_has_nul_byte(dn, dn_len)) {
zend_argument_value_error(2, "must not contain null bytes");
RETURN_THROWS();
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will do a follow-up to use the p ZPP modifier consistently for the DN parameter.

zend_hash_internal_pointer_reset(Z_ARRVAL_P(mods));
if (zend_hash_get_current_key_type(Z_ARRVAL_P(mods)) != HASH_KEY_IS_LONG) {
zend_argument_type_error(3, "must be integer-indexed");
SEPARATE_ARRAY(modification_zv);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure why we would need to separate the array as we are just doing validation and reading from it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because later on the code uses convert_to_* calls, but that means the zval may get transformed causing either corruption with opcache; or spooky unexpected changes at a distance.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahhhh okay thank you for the explanation.


zend_hash_move_forward(Z_ARRVAL_P(mod));
}
SEPARATE_ARRAY(modification_values_zv);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto, not sure why we would need this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto

Comment on lines +2700 to 2705
zend_string *modval = zval_get_string(modification_value_zv);
if (EG(exception)) {
RETVAL_FALSE;
ldap_mods[i]->mod_bvalues[j] = NULL;
num_mods = i + 1;
ldap_mods[modification_index]->mod_bvalues[value_index] = NULL;
num_mods = modification_index + 1;
goto cleanup;
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This case should probably be moved to the validation step ensuring that all values are strings.

@Girgias Girgias force-pushed the ldap-modify_batch-refactoring branch from 46a0773 to feccb4c Compare September 26, 2024 01:48
@Girgias Girgias requested a review from nielsdos September 26, 2024 01:48
@Girgias Girgias marked this pull request as ready for review September 26, 2024 01:48
Copy link
Member

@nielsdos nielsdos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found this hard to check because of the combination of indentation changes (which marks everything as changed) and semantic changes. I'd rather have a commit that changes the indentation and then the one after doing semantic changes. I realize it's not always possible to do this though.
Also a general thought: the arrays are validated but don't handle references, so you can get strange errors like "Option X must be of type Y, Y given"

--FILE--
<?php

/* We are assuming 3333 is not connectable */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if there's a reserved port or something like that we can use. I can imagine this test could be a tad bit flaky on some systems depending on the services running, unsure.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I picked this from another bug test, and it seems rather reliable

zend_hash_internal_pointer_reset(Z_ARRVAL_P(mods));
if (zend_hash_get_current_key_type(Z_ARRVAL_P(mods)) != HASH_KEY_IS_LONG) {
zend_argument_type_error(3, "must be integer-indexed");
SEPARATE_ARRAY(modification_zv);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because later on the code uses convert_to_* calls, but that means the zval may get transformed causing either corruption with opcache; or spooky unexpected changes at a distance.


zend_hash_move_forward(Z_ARRVAL_P(mod));
}
SEPARATE_ARRAY(modification_values_zv);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto

@Girgias
Copy link
Member Author

Girgias commented Sep 26, 2024

Right references, I always forget about them.

I will try to split the commit into different bits to make it more manageable.

@Girgias Girgias force-pushed the ldap-modify_batch-refactoring branch from feccb4c to 99982e5 Compare September 26, 2024 18:47
@Girgias Girgias force-pushed the ldap-modify_batch-refactoring branch from 99982e5 to 19b2dfb Compare September 27, 2024 12:42
@Girgias Girgias force-pushed the ldap-modify_batch-refactoring branch from 19b2dfb to 3759b81 Compare September 27, 2024 12:50
Copy link
Member

@nielsdos nielsdos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, splitting the commits helped a lot in reviewing.

@Girgias Girgias merged commit 8b0933b into php:master Sep 27, 2024
9 of 10 checks passed
@Girgias Girgias deleted the ldap-modify_batch-refactoring branch September 27, 2024 18:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants