Skip to content

Commit 0442c2a

Browse files
committed
Fix off-by-one bug when truncating tempnam prefix
The tempnam documentation currently states that "Only the first 63 characters of the prefix are used, the rest are ignored". However when the prefix is 64 characters-long, the current implementation fails to strip the last character, diverging from the documented behavior. This patch fixes the implementation so it matches the documented behavior for that specific case where the prefix is 64 characters long.
1 parent f7be15d commit 0442c2a

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

ext/standard/file.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -834,7 +834,7 @@ PHP_FUNCTION(tempnam)
834834
ZEND_PARSE_PARAMETERS_END();
835835

836836
p = php_basename(prefix, prefix_len, NULL, 0);
837-
if (ZSTR_LEN(p) > 64) {
837+
if (ZSTR_LEN(p) >= 64) {
838838
ZSTR_VAL(p)[63] = '\0';
839839
}
840840

0 commit comments

Comments
 (0)