Differential D21500 Diff 51171 src/lint/linter/xhpast/rules/ArcanistFormattedStringXHPASTLinterRule.php
Changeset View
Changeset View
Standalone View
Standalone View
src/lint/linter/xhpast/rules/ArcanistFormattedStringXHPASTLinterRule.php
Show First 20 Lines • Show All 88 Lines • ▼ Show 20 Lines | foreach ($function_calls as $call) { | ||||
// "qsprintf()" and other security-sensitive functions. | // "qsprintf()" and other security-sensitive functions. | ||||
continue; | continue; | ||||
} | } | ||||
$argv = array($format->evalStatic()) + array_fill(0, $argc, null); | $argv = array($format->evalStatic()) + array_fill(0, $argc, null); | ||||
try { | try { | ||||
xsprintf(null, null, $argv); | xsprintf( | ||||
'ArcanistFormattedStringXHPASTLinterRule::processXsprintfCallback', | |||||
null, | |||||
$argv); | |||||
} catch (BadFunctionCallException $ex) { | } catch (BadFunctionCallException $ex) { | ||||
$this->raiseLintAtNode( | $this->raiseLintAtNode( | ||||
$call, | $call, | ||||
str_replace('xsprintf', $name, $ex->getMessage())); | str_replace('xsprintf', $name, $ex->getMessage())); | ||||
} catch (InvalidArgumentException $ex) { | } catch (InvalidArgumentException $ex) { | ||||
// Ignore. | // Ignore. | ||||
} | } | ||||
} | } | ||||
} | } | ||||
public static function processXsprintfCallback( | |||||
$userdata, | |||||
&$pattern, | |||||
&$pos, | |||||
&$value, | |||||
&$length) { | |||||
if ($value !== null) { | |||||
throw new Exception('Expected dummy value to be null'); | |||||
} | |||||
// Turn format "%$pattern" with argument null into format "%s" with | |||||
// argument "%$pattern". This ensures we always provide valid input for | |||||
// sprintf to avoid getting a ValueError when using custom format | |||||
// specifiers. | |||||
$value = '%'.$pattern[$pos]; | |||||
$pattern[$pos] = 's'; | |||||
} | |||||
} | } |