2 Date: Mon, 18 Dec 2006 18:38:13 +0300
3 From: "Dmitry V. Levin" <ldv@altlinux.org>
4 Subject: gawk: do_match() invalid read
7 Due to missing mounds check, do_match() may do invalid read in multibyte
10 $ printf '\n\n' |env -i gawk '{print match(""," *")}'
13 $ printf '\n\n' |env -i LC_ALL=3Dru_RU.UTF-8 gawk '{print match(""," *")}'
17 As you see, match() output in multibyte locale is wrong; valgrind reports
18 about "Invalid read of size 4".
21 --- gawk-3.1.5/builtin.c.mbread 2007-01-12 13:23:55.000000000 +0100
22 +++ gawk-3.1.5/builtin.c 2007-01-12 13:24:41.000000000 +0100
25 rlength = REEND(rp, t1->stptr) - RESTART(rp, t1->stptr); /* byte length */
27 - if (gawk_mb_cur_max > 1) {
28 + if (rlength > 0 && gawk_mb_cur_max > 1) {
29 t1 = str2wstr(t1, & wc_indices);
30 rlength = wc_indices[rstart + rlength - 1] - wc_indices[rstart] + 1;
31 rstart = wc_indices[rstart];
34 subpat_len = len = SUBPATEND(rp, t1->stptr, ii) - s;
36 - if (gawk_mb_cur_max > 1) {
37 + if (len > 0 && gawk_mb_cur_max > 1) {
38 subpat_start = wc_indices[s];
39 subpat_len = wc_indices[s + len - 1] - subpat_start + 1;