From 50ab48b035c2555e09cc9ac94c74f45b74b234f4 Mon Sep 17 00:00:00 2001 From: Szabolcs Nagy Date: Fri, 19 Sep 2014 23:44:28 +0200 Subject: [PATCH] flockfile list corruption test --- src/regression/flockfile-list.c | 42 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/regression/flockfile-list.c diff --git a/src/regression/flockfile-list.c b/src/regression/flockfile-list.c new file mode 100644 index 0000000..09f18ff --- /dev/null +++ b/src/regression/flockfile-list.c @@ -0,0 +1,42 @@ +// commit: 3e936ce81bbbcc968f576aedbd5203621839f152 2014-09-19 +// flockfile linked list handling was broken +#include +#include +#include +#include +#include "test.h" + +int main() +{ + FILE *f = tmpfile(); + FILE *g = tmpfile(); + flockfile(g); + flockfile(f); + funlockfile(g); + fclose(g); + + /* fill memory */ + if (t_vmfill(0,0,0) < 0) + t_error("vmfill failed: %s\n", strerror(errno)); + size_t i,n; + unsigned char *p; + for (n = 1; n < 10000; n++) { + if (!(p=malloc(n))) break; + free(p); + } + n--; + if (!(p=malloc(n))) { + t_error("bad malloc fragmentation\n"); + return t_status; + } + memset(p, 0xff, n); + + /* may corrupt memory */ + funlockfile(f); + for (i=0; i