Skip to content

Commit

Permalink
Don't store null terminator in string buffer (#8)
Browse files Browse the repository at this point in the history
We were not accounting for the null terminator in the string allocation,
meaning that every string copy overflowed its buffer by one byte.

Usually the null terminator ended up getting overwritten by the first
character of the next string copied into the buffer, but occasionally,
due to concurrency, the null terminator from the first string could
overwrite the first character of the second.

Since the null terminator is not actually necessary, this commit removes
it from the string buffer. Now the allocation size is correct.

Co-authored-by: Evan Shaw <[email protected]>
  • Loading branch information
mreishus and edsrzf authored May 13, 2024
1 parent 326c246 commit 9bf98ed
Showing 1 changed file with 0 additions and 1 deletion.
1 change: 0 additions & 1 deletion zend_tombs_strings.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ static zend_always_inline zend_tombs_string_t* zend_tombs_strings_copy(zend_stri
ZSTR_VAL(string),
ZSTR_LEN(string));

copy->value[ZSTR_LEN(string)] = 0;
copy->hash = ZSTR_HASH(string);

__atomic_store_n(&copy->length, ZSTR_LEN(string), __ATOMIC_SEQ_CST);
Expand Down

0 comments on commit 9bf98ed

Please sign in to comment.