Skip to content

Commit

Permalink
Fix password_hash algo constant passing on PHP <7.4
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Mar 16, 2024
1 parent 969ff31 commit fc4e589
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion resources/functionMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -8487,7 +8487,7 @@
'parsekit_func_arginfo' => ['array', 'function'=>'mixed'],
'passthru' => ['void', 'command'=>'string', '&w_return_value='=>'int'],
'password_get_info' => ['array', 'hash'=>'string'],
'password_hash' => ['__benevolent<non-empty-string|false|null>', 'password'=>'string', 'algo'=>'int', 'options='=>'array'],
'password_hash' => ['__benevolent<non-empty-string|false|null>', 'password'=>'string', 'algo'=>'string|int', 'options='=>'array'],
'password_make_salt' => ['bool', 'password'=>'string', 'hash'=>'string'],
'password_needs_rehash' => ['bool', 'hash'=>'string', 'algo'=>'int', 'options='=>'array'],
'password_verify' => ['bool', 'password'=>'string', 'hash'=>'string'],
Expand Down
1 change: 0 additions & 1 deletion resources/functionMap_php74delta.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
'get_mangled_object_vars' => ['array', 'obj'=>'object'],
'mb_str_split' => ['list<string>|false', 'str'=>'string', 'split_length='=>'int', 'encoding='=>'string'],
'password_algos' => ['list<string>'],
'password_hash' => ['__benevolent<string|false|null>', 'password'=>'string', 'algo'=>'string|null', 'options='=>'array'],
'password_needs_rehash' => ['bool', 'hash'=>'string', 'algo'=>'string|null', 'options='=>'array'],
'preg_replace_callback' => ['string|array|null', 'regex'=>'string|array', 'callback'=>'callable(array<int|string, string>):string', 'subject'=>'string|array', 'limit='=>'int', '&w_count='=>'int', 'flags='=>'int'],
'preg_replace_callback_array' => ['string|array|null', 'pattern'=>'array<string,callable>', 'subject'=>'string|array', 'limit='=>'int', '&w_count='=>'int', 'flags='=>'int'],
Expand Down
4 changes: 2 additions & 2 deletions resources/functionMap_php80delta.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
'mktime' => ['int|false', 'hour'=>'int', 'minute='=>'int', 'second='=>'int', 'month='=>'int', 'day='=>'int', 'year='=>'int'],
'odbc_exec' => ['resource|false', 'connection_id'=>'resource', 'query'=>'string'],
'parse_str' => ['void', 'encoded_string'=>'string', '&w_result'=>'array'],
'password_hash' => ['string', 'password'=>'string', 'algo'=>'string|int|null', 'options='=>'array'],
'password_hash' => ['non-empty-string', 'password'=>'string', 'algo'=>'string|int|null', 'options='=>'array'],
'PDOStatement::fetchAll' => ['array', 'how='=>'int', 'fetch_argument='=>'int|string|callable', 'ctor_args='=>'?array'],
'PhpToken::tokenize' => ['list<PhpToken>', 'code'=>'string', 'flags='=>'int'],
'PhpToken::is' => ['bool', 'kind'=>'string|int|string[]|int[]'],
Expand Down Expand Up @@ -226,7 +226,7 @@
'money_format' => ['string', 'format'=>'string', 'value'=>'float'],
'odbc_exec' => ['resource|false', 'connection_id'=>'resource', 'query'=>'string', 'flags='=>'int'],
'parse_str' => ['void', 'encoded_string'=>'string', '&w_result='=>'array'],
'password_hash' => ['string|false|null', 'password'=>'string', 'algo'=>'?string|?int', 'options='=>'array'],
'password_hash' => ['__benevolent<non-empty-string|false|null>', 'password'=>'string', 'algo'=>'string|int', 'options='=>'array'],
'png2wbmp' => ['bool', 'pngname'=>'string', 'wbmpname'=>'string', 'dest_height'=>'int', 'dest_width'=>'int', 'threshold'=>'int'],
'proc_get_status' => ['array{command: string, pid: int, running: bool, signaled: bool, stopped: bool, exitcode: int, termsig: int, stopsig: int}|false', 'process'=>'resource'],
'read_exif_data' => ['array', 'filename'=>'string', 'sections_needed='=>'string', 'sub_arrays='=>'bool', 'read_thumbnail='=>'bool'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -917,11 +917,11 @@ public function testBug5978(): void
if (PHP_VERSION_ID >= 80000) {
$expectedErrors = [
[
'Strict comparison using === between string and false will always evaluate to false.',
'Strict comparison using === between non-empty-string and false will always evaluate to false.',
7,
],
[
'Strict comparison using === between string and null will always evaluate to false.',
'Strict comparison using === between non-empty-string and null will always evaluate to false.',
7,
],
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1641,4 +1641,9 @@ public function testBug10626(): void
]);
}

public function testArgon2PasswordHash(): void
{
$this->analyse([__DIR__ . '/data/argon2id-password-hash.php'], []);
}

}
7 changes: 7 additions & 0 deletions tests/PHPStan/Rules/Functions/data/argon2id-password-hash.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

namespace Argon2IdPasswordHash;

function (): void {
password_hash('my strong password', PASSWORD_ARGON2ID);
};

0 comments on commit fc4e589

Please sign in to comment.