Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions ext/hash/hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -414,8 +414,8 @@ PHP_FUNCTION(hash_init)

#define PHP_HASHCONTEXT_VERIFY(func, hash) { \
if (!hash->context) { \
php_error(E_WARNING, "%s(): supplied resource is not a valid Hash Context resource", func); \
RETURN_NULL(); \
zend_throw_error(NULL, "%s(): supplied resource is not a valid Hash Context resource", func); \
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be a TypeError? See discussion on #4643

Copy link
Member

Choose a reason for hiding this comment

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

Not really the same case, more a bad error message. It should probably say something along the lines of "can't reuse an already finalized HashContext" or so.

Copy link
Contributor

Choose a reason for hiding this comment

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

Gotcha. 👍

return; \
} \
}

Expand Down Expand Up @@ -585,7 +585,9 @@ PHP_FUNCTION(hash_copy)

if (php_hashcontext_from_object(Z_OBJ_P(return_value))->context == NULL) {
zval_ptr_dtor(return_value);
RETURN_FALSE;

zend_throw_error(NULL, "Cannot copy hash");
return;
}
}
/* }}} */
Expand Down
12 changes: 9 additions & 3 deletions ext/hash/tests/reuse.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ Hash: Attempt to reuse a closed hash context

$h = hash_init('md5');
hash_final($h);
hash_update($h, 'foo');
--EXPECTF--
Warning: hash_update(): supplied resource is not a valid Hash Context resource in %s%eext%ehash%etests%ereuse.php on line %d
try {
hash_update($h, 'foo');
}
catch (\Error $e) {
echo $e->getMessage() . "\n";
}

--EXPECT--
hash_update(): supplied resource is not a valid Hash Context resource