Skip to content

Commit 69a49af

Browse files
Zenjuweltling
authored andcommitted
Fix out-of bounds access
Test case: strnatcmp_ex(L"333", 3, L"333 ", 4, true) The reason this bug didn't come up earlier is probably because most input strings are null-terminated.
1 parent b37dafc commit 69a49af

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

ext/standard/strnatcmp.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,10 @@ PHPAPI int strnatcmp_ex(char const *a, size_t a_len, char const *b, size_t b_len
141141
else if (ap == aend && bp == bend)
142142
/* End of the strings. Let caller sort them out. */
143143
return 0;
144+
else if (ap == aend)
145+
return -1;
146+
else if (bp == bend)
147+
return 1;
144148
else {
145149
/* Keep on comparing from the current point. */
146150
ca = *ap; cb = *bp;

0 commit comments

Comments
 (0)