Skip to content

Conversation

Girgias
Copy link
Member

@Girgias Girgias commented Feb 21, 2024

No description provided.

@Girgias Girgias marked this pull request as ready for review February 21, 2024 23:07
ptr2 = php_ffi_parse_cdata_or_string_to_ptr(size, op2_obj, op2_zstr, &is_error);
if (is_error) {
if (op2_zstr) {
zend_throw_error(zend_ffi_exception_ce, "attempt to read over string boundary");
Copy link
Member

Choose a reason for hiding this comment

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

missing RETURN_THROWS(); here and below

Copy link
Member

Choose a reason for hiding this comment

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

Ah, I guess it's not missing, I just didn't notice the one at line 4532 (the diff is a bit clunky)

Copy link
Member

@dstogov dstogov left a comment

Choose a reason for hiding this comment

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

The PR name looks weird. ZPP is abbreviation to Zend Parameter Parsing.

The patch only adds information about types of FFI::memcpy() and FFI::memset() arguments.

I'm indifferent to this change.

Comment on lines -1764 to +1765
#define Z_PARAM_OBJ_OF_CLASS_OR_STR_EX(destination_object, base_ce, destination_string, allow_null) \
Z_PARAM_PROLOGUE(0, 0); \
#define Z_PARAM_OBJ_OF_CLASS_OR_STR_EX(destination_object, base_ce, destination_string, allow_null, deref) \
Z_PARAM_PROLOGUE(deref, 0); \
Copy link
Member

Choose a reason for hiding this comment

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

The change of prototype may affect other users.

Comment on lines +4385 to +4423
static void *php_ffi_parse_cdata_to_ptr(zend_long size, zend_object *zobj, bool *is_error)
{
void *result_ptr = NULL;
*is_error = false;

zend_ffi_cdata *cdata = (zend_ffi_cdata*)zobj;
zend_ffi_type *type = ZEND_FFI_TYPE(cdata->type);

if (type->kind == ZEND_FFI_TYPE_POINTER) {
result_ptr = *(void**)cdata->ptr;
} else {
if (type->kind != ZEND_FFI_TYPE_POINTER && size > type->size) {
*is_error = true;
return NULL;
}
result_ptr = cdata->ptr;
}

return result_ptr;
}

static void *php_ffi_parse_cdata_or_string_to_ptr(zend_long size, zend_object *zobj, zend_string *zstr, bool *is_error)
{
void *result_ptr = NULL;
*is_error = false;

if (zstr) {
if (size > ZSTR_LEN(zstr)) {
*is_error = true;
return NULL;
}
result_ptr = ZSTR_VAL(zstr);
} else {
result_ptr = php_ffi_parse_cdata_to_ptr(size, zobj, is_error);
}

return result_ptr;
}

Copy link
Member

Choose a reason for hiding this comment

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

The separation of this functions doesn't make things more clear, because you delegated them to check for data/string size and this became unclear.

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.

3 participants