Skip to content

Support the actual #[\SensitiveParameter] attribute in stubs #8836

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

Merged
merged 6 commits into from
Jul 12, 2022

Conversation

TimWolla
Copy link
Member

see #8689
see #8776

@bwoebi
Copy link
Member

bwoebi commented Jul 5, 2022

I suppose we can now also get rid of zend_mark_function_parameter_as_sensitive() and replace it by a proper mechanism akin to #8839 for arbitrary attributes.

@TimWolla
Copy link
Member Author

TimWolla commented Jul 5, 2022

@bwoebi Was already working on it. Pushed now, PTAL 😃

Comment on lines -835 to +846
&& $this->defaultValue === $other->defaultValue
&& $this->isSensitive === $other->isSensitive;
&& $this->defaultValue === $other->defaultValue;
Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure about this part. I don't believe that attributes need to be part of equals(), as they are not part of the ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX stuff.

@TimWolla TimWolla force-pushed the sensitive-parameter-attribute-stub branch from 06ecf2b to 5820abe Compare July 12, 2022 08:39
@TimWolla
Copy link
Member Author

Rebased for #8931.

Copy link
Member

@kocsismate kocsismate 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 overall, I only had 2 minor questions/suggestions.

if ($funcInfo->name instanceof MethodName) {
$functionTable = "&class_entry->function_table";
} else {
$functionTable = "CG(function_table)";
}

$code .= "\tzend_mark_function_parameter_as_sensitive($functionTable, \"" . $funcInfo->name->getNameForAttributes() . "\", $index);\n";
foreach ($arg->attributes as $attribute) {
$code .= $attribute->generateCode("zend_add_parameter_attribute(zend_hash_str_find_ptr($functionTable, \"" . $funcInfo->name->getNameForAttributes() . "\", sizeof(\"" . $funcInfo->name->getNameForAttributes() . "\") - 1), $index", "{$funcInfo->getArgInfoName()}_arg{$index}", $allConstInfos);
Copy link
Member

Choose a reason for hiding this comment

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

I don't really like the fact that $funcInfo->getArgInfoName() is used for generating the attribute name, because the arginfo_ part is unnecessary (and I didn't realize for a while why it's there). Even though the format of $funcInfo->name->getMethodSynopsisFilename() looks a bit better, it would be weird to use this name here.. So either we should rename this method (getSnakeCasedName??) or just leave the name as-is.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks! $funcInfo->name->getMethodSynopsisFilename() is indeed much better. It's was hard for me to "discover" something appropriate to use and ->getArgInfoName() worked.

zend_mark_function_parameter_as_sensitive(CG(function_table), "openssl_pkey_derive", 1);
zend_mark_function_parameter_as_sensitive(CG(function_table), "openssl_spki_new", 0);

zend_string *attribute_name_SensitiveParameter_arginfo_openssl_x509_check_private_key_arg1 = zend_string_init("SensitiveParameter", sizeof("SensitiveParameter") - 1, 1);
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 it would be beneficial to declare the different attribute names first and then use them in the zend_add_parameter_attribute() invocations. It would save quite a few lines when an extension has a lot of attributes with the same name

Copy link
Member Author

Choose a reason for hiding this comment

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

It likely would, but that should probably be a follow-up, as it also affects the class attributes.

@TimWolla
Copy link
Member Author

@kocsismate Thanks for the review! I've made the requested changes. Feel free to merge if you are happy with the new version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment