diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-11 08:21:29 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-11 08:21:29 +0000 |
commit | 29cd838eab01ed7110f3ccb2e8c6a35c8a31dbcc (patch) | |
tree | 63ef546b10a81d461e5cf5ed9e98a68cd7dee1aa /src/sed/testsuite/bug-regex15.c | |
parent | Initial commit. (diff) | |
download | kbuild-29cd838eab01ed7110f3ccb2e8c6a35c8a31dbcc.tar.xz kbuild-29cd838eab01ed7110f3ccb2e8c6a35c8a31dbcc.zip |
Adding upstream version 1:0.1.9998svn3589+dfsg.upstream/1%0.1.9998svn3589+dfsg
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/sed/testsuite/bug-regex15.c')
-rw-r--r-- | src/sed/testsuite/bug-regex15.c | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/src/sed/testsuite/bug-regex15.c b/src/sed/testsuite/bug-regex15.c new file mode 100644 index 0000000..c7eddf7 --- /dev/null +++ b/src/sed/testsuite/bug-regex15.c @@ -0,0 +1,47 @@ +/* Test for memory/CPU leak in regcomp. */ + +#include <sys/types.h> +#include <sys/time.h> +#include <sys/resource.h> +#include <regex.h> +#include <stdio.h> +#include <stdlib.h> + +#define TEST_DATA_LIMIT (32 << 20) + +int +main () +{ +#ifdef RLIMIT_DATA + regex_t re; + int reerr; + + /* Try to avoid eating all memory if a test leaks. */ + struct rlimit data_limit; + if (getrlimit (RLIMIT_DATA, &data_limit) == 0) + { + if ((rlim_t) TEST_DATA_LIMIT > data_limit.rlim_max) + data_limit.rlim_cur = data_limit.rlim_max; + else if (data_limit.rlim_cur > (rlim_t) TEST_DATA_LIMIT) + data_limit.rlim_cur = (rlim_t) TEST_DATA_LIMIT; + if (setrlimit (RLIMIT_DATA, &data_limit) < 0) + perror ("setrlimit: RLIMIT_DATA"); + } + else + perror ("getrlimit: RLIMIT_DATA"); + + reerr = regcomp (&re, "^6?3?[25]?5?[14]*[25]*[69]*+[58]*87?4?$", + REG_EXTENDED | REG_NOSUB); + if (reerr != 0) + { + char buf[100]; + regerror (reerr, &re, buf, sizeof buf); + printf ("regerror %s\n", buf); + return 1; + } + + return 0; +#else + return 77; +#endif +} |