-
Notifications
You must be signed in to change notification settings - Fork 7.9k
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
Changes from 5 commits
085add0
b9e67fd
7075706
3f62f35
5820abe
1424e85
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -815,33 +815,35 @@ class ArgInfo { | |
public $phpDocType; | ||
/** @var string|null */ | ||
public $defaultValue; | ||
/** @var bool */ | ||
public $isSensitive; | ||
/** @var AttributeInfo[] */ | ||
public $attributes; | ||
|
||
/** | ||
* @param AttributeInfo[] $attributes | ||
*/ | ||
public function __construct( | ||
string $name, | ||
int $sendBy, | ||
bool $isVariadic, | ||
?Type $type, | ||
?Type $phpDocType, | ||
?string $defaultValue, | ||
bool $isSensitive | ||
array $attributes | ||
) { | ||
$this->name = $name; | ||
$this->sendBy = $sendBy; | ||
$this->isVariadic = $isVariadic; | ||
$this->setTypes($type, $phpDocType); | ||
$this->defaultValue = $defaultValue; | ||
$this->isSensitive = $isSensitive; | ||
$this->attributes = $attributes; | ||
} | ||
|
||
public function equals(ArgInfo $other): bool { | ||
return $this->name === $other->name | ||
&& $this->sendBy === $other->sendBy | ||
&& $this->isVariadic === $other->isVariadic | ||
&& Type::equals($this->type, $other->type) | ||
&& $this->defaultValue === $other->defaultValue | ||
&& $this->isSensitive === $other->isSensitive; | ||
&& $this->defaultValue === $other->defaultValue; | ||
} | ||
|
||
public function getSendByString(): string { | ||
|
@@ -2570,7 +2572,7 @@ function (Name $item) { | |
} | ||
} | ||
|
||
if ($attributeInitializationCode = generateAttributeInitialization($this->funcInfos, $this->cond)) { | ||
if ($attributeInitializationCode = generateAttributeInitialization($this->funcInfos, $this->cond, $allConstInfos)) { | ||
if (!$php82MinimumCompatibility) { | ||
$code .= "#if (PHP_VERSION_ID >= " . PHP_82_VERSION_ID . ")\n"; | ||
} | ||
|
@@ -3151,7 +3153,7 @@ public function getVariableName(): string { | |
|
||
if ($this->name === "param") { | ||
preg_match('/^\s*[\w\|\\\\\[\]]+\s*\$(\w+).*$/', $value, $matches); | ||
} elseif ($this->name === "prefer-ref" || $this->name === "sensitive-param") { | ||
} elseif ($this->name === "prefer-ref") { | ||
preg_match('/^\s*\$(\w+).*$/', $value, $matches); | ||
} | ||
|
||
|
@@ -3242,7 +3244,6 @@ function parseFunctionLike( | |
break; | ||
|
||
case 'prefer-ref': | ||
case 'sensitive-param': | ||
$varName = $tag->getVariableName(); | ||
if (!isset($paramMeta[$varName])) { | ||
$paramMeta[$varName] = []; | ||
|
@@ -3260,7 +3261,12 @@ function parseFunctionLike( | |
foreach ($func->getParams() as $i => $param) { | ||
$varName = $param->var->name; | ||
$preferRef = !empty($paramMeta[$varName]['prefer-ref']); | ||
$isSensitive = !empty($paramMeta[$varName]['sensitive-param']); | ||
$attributes = []; | ||
foreach ($param->attrGroups as $attrGroup) { | ||
foreach ($attrGroup->attrs as $attr) { | ||
$attributes[] = new AttributeInfo($attr->name->toString(), $attr->args); | ||
} | ||
} | ||
unset($paramMeta[$varName]); | ||
|
||
if (isset($varNameSet[$varName])) { | ||
|
@@ -3308,7 +3314,7 @@ function parseFunctionLike( | |
$type, | ||
isset($docParamTypes[$varName]) ? Type::fromString($docParamTypes[$varName]) : null, | ||
$param->default ? $prettyPrinter->prettyPrintExpr($param->default) : null, | ||
$isSensitive | ||
$attributes | ||
); | ||
if (!$param->default && !$param->variadic) { | ||
$numRequiredArgs = $i + 1; | ||
|
@@ -3962,7 +3968,7 @@ static function (FuncInfo $funcInfo) use ($fileInfo, &$generatedFunctionDeclarat | |
} | ||
|
||
if ($fileInfo->generateClassEntries) { | ||
$attributeInitializationCode = generateAttributeInitialization($fileInfo->funcInfos); | ||
$attributeInitializationCode = generateAttributeInitialization($fileInfo->funcInfos, null, $allConstInfos); | ||
|
||
if ($attributeInitializationCode !== "" || !empty($fileInfo->constInfos)) { | ||
$code .= "\nstatic void register_{$stubFilenameWithoutExtension}_symbols(int module_number)\n"; | ||
|
@@ -4029,25 +4035,23 @@ function generateFunctionEntries(?Name $className, array $funcInfos, ?string $co | |
/** | ||
* @param iterable<FuncInfo> $funcInfos | ||
*/ | ||
function generateAttributeInitialization(iterable $funcInfos, ?string $parentCond = null): string { | ||
function generateAttributeInitialization(iterable $funcInfos, ?string $parentCond = null, iterable $allConstInfos): string { | ||
return generateCodeWithConditions( | ||
$funcInfos, | ||
"", | ||
static function (FuncInfo $funcInfo) { | ||
static function (FuncInfo $funcInfo) use ($allConstInfos) { | ||
$code = null; | ||
|
||
foreach ($funcInfo->args as $index => $arg) { | ||
if (!$arg->isSensitive) { | ||
continue; | ||
} | ||
|
||
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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't really like the fact that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks! |
||
} | ||
} | ||
|
||
return $code; | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
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 theZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX
stuff.