regex memory corruption regression test
[libc-test] / src / regression / flockfile-list.c
1 // commit: 3e936ce81bbbcc968f576aedbd5203621839f152 2014-09-19
2 // flockfile linked list handling was broken
3 #include <errno.h>
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <string.h>
7 #include "test.h"
8
9 int main()
10 {
11         FILE *f = tmpfile();
12         FILE *g = tmpfile();
13         flockfile(g);
14         flockfile(f);
15         funlockfile(g);
16         fclose(g);
17
18         /* fill memory */
19         if (t_vmfill(0,0,0) < 0)
20                 t_error("vmfill failed: %s\n", strerror(errno));
21         size_t i,n;
22         unsigned char *p;
23         for (n = 1; n < 10000; n++) {
24                 if (!(p=malloc(n))) break;
25                 free(p);
26         }
27         n--;
28         if (!(p=malloc(n))) {
29                 t_error("bad malloc fragmentation\n");
30                 return t_status;
31         }
32         memset(p, 0xff, n);
33
34         /* may corrupt memory */
35         funlockfile(f);
36         for (i=0; i<n; i++) {
37                 if (p[i]!=0xff) {
38                         t_error("p[%zu] = %.2x\n", i, p[i]);
39                 }
40         }
41         return t_status;
42 }