[ruby/prism] Only read from buffer if size is greater than 0

It looks like we can possibly do an out of bounds read if size is equal
to 0.  This commit adds a conditional to ensure size is actually greater
than 0 before looking backwards in the buffer

2031b626e6
This commit is contained in:
Aaron Patterson 2024-10-28 13:21:14 -07:00 committed by git
parent 83568a41af
commit 3c9be02af1

View file

@ -185,7 +185,7 @@ pm_strspn_number_kind_underscores(const uint8_t *string, ptrdiff_t length, const
size++;
}
if (string[size - 1] == '_') *invalid = string + size - 1;
if (size > 0 && string[size - 1] == '_') *invalid = string + size - 1;
return size;
}