mirror of
https://github.com/janet-lang/janet
synced 2026-11-23 15:47:11 +00:00
make peg check more paranoid, check at runtime too
This commit is contained in:
2 files changed
+3
-4
No files matched your search
+1
-4
@@ -426,7 +426,7 @@ tail:
|
||||
|
||||
case RULE_ARGUMENT: {
|
||||
int32_t index = ((int32_t *)rule)[1];
|
||||
Janet capture = (index >= s->extrac) ? janet_wrap_nil() : s->extrav[index];
|
||||
Janet capture = (index >= s->extrac || index < 0) ? janet_wrap_nil() : s->extrav[index];
|
||||
pushcap(s, capture, rule[2]);
|
||||
return text;
|
||||
}
|
||||
@@ -1764,9 +1764,6 @@ static void *peg_unmarshal(JanetMarshalContext *ctx) {
|
||||
case RULE_ARGUMENT:
|
||||
/* [argument-index, tag] */
|
||||
OVERFLOW_CHECK(3);
|
||||
/* index is read as a signed int32 at match time and only
|
||||
* bounds-checked against extrac on the high side, so a
|
||||
* negative index would read before extrav */
|
||||
if (((int32_t) rule[1]) < 0) goto bad;
|
||||
i += 3;
|
||||
break;
|
||||
|
||||
@@ -963,6 +963,8 @@
|
||||
|
||||
```))
|
||||
|
||||
(assert-error "negative argument" (peg/compile ~(argument -1)))
|
||||
|
||||
# A matchtime or replacement callback that grows the buffer being matched
|
||||
# reallocates its storage. The matcher kept pointing at the old allocation,
|
||||
# so the rest of the match read freed memory.
|
||||
|
||||
Reference in new issue
Block a user