diff options
author | Aaron Patterson <[email protected]> | 2024-10-28 13:21:14 -0700 |
---|---|---|
committer | git <[email protected]> | 2024-10-28 20:38:20 +0000 |
commit | 3c9be02af1e44a79191309cf727ede20cc576cb0 (patch) | |
tree | 1b01e3a66f6f0a9adc35f75955926f109d6eed48 | |
parent | 83568a41afade809e03fdadd5f4026488920b293 (diff) |
[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
https://github.com/ruby/prism/commit/2031b626e6
-rw-r--r-- | prism/util/pm_char.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/prism/util/pm_char.c b/prism/util/pm_char.c index dce19abd1b..a51dc11645 100644 --- a/prism/util/pm_char.c +++ b/prism/util/pm_char.c @@ -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; } |