glibc: backport fix for regexec buffer read overrun
[openwrt/.git] / toolchain / glibc / patches / 001-regex-read-overrun.patch
1 commit 583dd860d5b833037175247230a328f0050dbfe9
2 Author: Paul Eggert <eggert@cs.ucla.edu>
3 Date:   Mon Jan 21 11:08:13 2019 -0800
4
5     regex: fix read overrun [BZ #24114]
6     
7     Problem found by AddressSanitizer, reported by Hongxu Chen in:
8     https://debbugs.gnu.org/34140
9     * posix/regexec.c (proceed_next_node):
10     Do not read past end of input buffer.
11
12 --- a/posix/regexec.c
13 +++ b/posix/regexec.c
14 @@ -1293,8 +1293,10 @@ proceed_next_node (const re_match_context_t *mctx, Idx nregs, regmatch_t *regs,
15               else if (naccepted)
16                 {
17                   char *buf = (char *) re_string_get_buffer (&mctx->input);
18 -                 if (memcmp (buf + regs[subexp_idx].rm_so, buf + *pidx,
19 -                             naccepted) != 0)
20 +                 if (mctx->input.valid_len - *pidx < naccepted
21 +                     || (memcmp (buf + regs[subexp_idx].rm_so, buf + *pidx,
22 +                                 naccepted)
23 +                         != 0))
24                     return -1;
25                 }
26             }