Commit 3d1e1460 authored by Guido van Rossum's avatar Guido van Rossum

Improve check for offset out of range

parent f2c8beba
...@@ -98,6 +98,10 @@ reg_match(re, args) ...@@ -98,6 +98,10 @@ reg_match(re, args)
err_clear(); err_clear();
if (!getargs(args, "(s#i)", &buffer, &size, &offset)) if (!getargs(args, "(s#i)", &buffer, &size, &offset))
return NULL; return NULL;
if (offset < 0 || offset > size) {
err_setstr(RegexError, "match offset out of range");
return NULL;
}
} }
re->re_regs_valid = 0; re->re_regs_valid = 0;
result = re_match(&re->re_patbuf, buffer, size, offset, &re->re_regs); result = re_match(&re->re_patbuf, buffer, size, offset, &re->re_regs);
...@@ -128,10 +132,10 @@ reg_search(re, args) ...@@ -128,10 +132,10 @@ reg_search(re, args)
err_clear(); err_clear();
if (!getargs(args, "(s#i)", &buffer, &size, &offset)) if (!getargs(args, "(s#i)", &buffer, &size, &offset))
return NULL; return NULL;
} if (offset < 0 || offset > size) {
if (offset < 0 || offset > size) { err_setstr(RegexError, "search offset out of range");
err_setstr(RegexError, "search offset out of range"); return NULL;
return NULL; }
} }
/* NB: In Emacs 18.57, the documentation for re_search[_2] and /* NB: In Emacs 18.57, the documentation for re_search[_2] and
the implementation don't match: the documentation states that the implementation don't match: the documentation states that
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment