summaryrefslogtreecommitdiffstats
path: root/Modules/regexmodule.c
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1992-09-03 20:35:01 (GMT)
committerGuido van Rossum <guido@python.org>1992-09-03 20:35:01 (GMT)
commit3d1e146086ec308cb14416ed606bf6160e569878 (patch)
treeb3db73374337c96b4ae34dd541e297ea50ce71c5 /Modules/regexmodule.c
parentf2c8beba0b818f59ffc65abfff6cbfbb0efe04de (diff)
downloadcpython-3d1e146086ec308cb14416ed606bf6160e569878.zip
cpython-3d1e146086ec308cb14416ed606bf6160e569878.tar.gz
cpython-3d1e146086ec308cb14416ed606bf6160e569878.tar.bz2
Improve check for offset out of range
Diffstat (limited to 'Modules/regexmodule.c')
-rw-r--r--Modules/regexmodule.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/Modules/regexmodule.c b/Modules/regexmodule.c
index 77daa77..6afe3b7 100644
--- a/Modules/regexmodule.c
+++ b/Modules/regexmodule.c
@@ -98,6 +98,10 @@ reg_match(re, args)
err_clear();
if (!getargs(args, "(s#i)", &buffer, &size, &offset))
return NULL;
+ if (offset < 0 || offset > size) {
+ err_setstr(RegexError, "match offset out of range");
+ return NULL;
+ }
}
re->re_regs_valid = 0;
result = re_match(&re->re_patbuf, buffer, size, offset, &re->re_regs);
@@ -128,10 +132,10 @@ reg_search(re, args)
err_clear();
if (!getargs(args, "(s#i)", &buffer, &size, &offset))
return NULL;
- }
- if (offset < 0 || offset > size) {
- err_setstr(RegexError, "search offset out of range");
- return NULL;
+ if (offset < 0 || offset > size) {
+ err_setstr(RegexError, "search offset out of range");
+ return NULL;
+ }
}
/* NB: In Emacs 18.57, the documentation for re_search[_2] and
the implementation don't match: the documentation states that