Mercurial > hg > octave-lojdl > gnulib-hg
comparison m4/regex.m4 @ 17305:0e5a583a2a8d
regex: test for buffer overrun
* m4/regex.m4 (gl_REGEX): Add test case, by Andreas Schwab,
for the just-fixed regex bug.
author | Paul Eggert <eggert@cs.ucla.edu> |
---|---|
date | Tue, 29 Jan 2013 22:34:58 -0800 |
parents | e542fd46ad6f |
children | 19e841152153 |
comparison
equal
deleted
inserted
replaced
17304:d08258969ee9 | 17305:0e5a583a2a8d |
---|---|
1 # serial 61 | 1 # serial 62 |
2 | 2 |
3 # Copyright (C) 1996-2001, 2003-2013 Free Software Foundation, Inc. | 3 # Copyright (C) 1996-2001, 2003-2013 Free Software Foundation, Inc. |
4 # | 4 # |
5 # This file is free software; the Free Software Foundation | 5 # This file is free software; the Free Software Foundation |
6 # gives unlimited permission to copy and/or distribute it, | 6 # gives unlimited permission to copy and/or distribute it, |
41 unsigned char folded_chars[UCHAR_MAX + 1]; | 41 unsigned char folded_chars[UCHAR_MAX + 1]; |
42 int i; | 42 int i; |
43 const char *s; | 43 const char *s; |
44 struct re_registers regs; | 44 struct re_registers regs; |
45 | 45 |
46 /* http://sourceware.org/ml/libc-hacker/2006-09/msg00008.html | |
47 This test needs valgrind to catch the bug on Debian | |
48 GNU/Linux 3.1 x86, but it might catch the bug better | |
49 on other platforms and it shouldn't hurt to try the | |
50 test here. */ | |
51 if (setlocale (LC_ALL, "en_US.UTF-8")) | 46 if (setlocale (LC_ALL, "en_US.UTF-8")) |
52 { | 47 { |
53 static char const pat[] = "insert into"; | 48 { |
54 static char const data[] = | 49 /* http://sourceware.org/ml/libc-hacker/2006-09/msg00008.html |
55 "\xFF\0\x12\xA2\xAA\xC4\xB1,K\x12\xC4\xB1*\xACK"; | 50 This test needs valgrind to catch the bug on Debian |
56 re_set_syntax (RE_SYNTAX_GREP | RE_HAT_LISTS_NOT_NEWLINE | 51 GNU/Linux 3.1 x86, but it might catch the bug better |
57 | RE_ICASE); | 52 on other platforms and it shouldn't hurt to try the |
58 memset (®ex, 0, sizeof regex); | 53 test here. */ |
59 s = re_compile_pattern (pat, sizeof pat - 1, ®ex); | 54 static char const pat[] = "insert into"; |
60 if (s) | 55 static char const data[] = |
61 result |= 1; | 56 "\xFF\0\x12\xA2\xAA\xC4\xB1,K\x12\xC4\xB1*\xACK"; |
62 else if (re_search (®ex, data, sizeof data - 1, | 57 re_set_syntax (RE_SYNTAX_GREP | RE_HAT_LISTS_NOT_NEWLINE |
63 0, sizeof data - 1, ®s) | 58 | RE_ICASE); |
64 != -1) | 59 memset (®ex, 0, sizeof regex); |
65 result |= 1; | 60 s = re_compile_pattern (pat, sizeof pat - 1, ®ex); |
61 if (s) | |
62 result |= 1; | |
63 else if (re_search (®ex, data, sizeof data - 1, | |
64 0, sizeof data - 1, ®s) | |
65 != -1) | |
66 result |= 1; | |
67 } | |
68 | |
69 { | |
70 /* This test is from glibc bug 15078. | |
71 The test case is from Andreas Schwab in | |
72 <http://www.sourceware.org/ml/libc-alpha/2013-01/msg00967.html>. | |
73 */ | |
74 static char const pat[] = "[^x]x"; | |
75 static char const data[] = | |
76 "\xe1\x80\x80\xe1\x80\xbb\xe1\x80\xbd\xe1\x80\x94\xe1\x80" | |
77 "\xba\xe1\x80\xaf\xe1\x80\x95\xe1\x80\xbax"; | |
78 re_set_syntax (0); | |
79 memset (®ex, 0, sizeof regex); | |
80 s = re_compile_pattern (pat, sizeof pat - 1, ®ex); | |
81 if (s) | |
82 result |= 1; | |
83 else if (re_search (®ex, data, sizeof data - 1, | |
84 0, sizeof data - 1, 0) | |
85 != 20) | |
86 result |= 1; | |
87 } | |
88 | |
66 if (! setlocale (LC_ALL, "C")) | 89 if (! setlocale (LC_ALL, "C")) |
67 return 1; | 90 return 1; |
68 } | 91 } |
69 | 92 |
70 /* This test is from glibc bug 3957, reported by Andrew Mackey. */ | 93 /* This test is from glibc bug 3957, reported by Andrew Mackey. */ |