flockfile list corruption test
authorSzabolcs Nagy <nsz@port70.net>
Fri, 19 Sep 2014 21:44:28 +0000 (23:44 +0200)
committerSzabolcs Nagy <nsz@port70.net>
Fri, 19 Sep 2014 21:44:28 +0000 (23:44 +0200)
src/regression/flockfile-list.c [new file with mode: 0644]

diff --git a/src/regression/flockfile-list.c b/src/regression/flockfile-list.c
new file mode 100644 (file)
index 0000000..09f18ff
--- /dev/null
@@ -0,0 +1,42 @@
+// commit: 3e936ce81bbbcc968f576aedbd5203621839f152 2014-09-19
+// flockfile linked list handling was broken
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#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<n; i++) {
+               if (p[i]!=0xff) {
+                       t_error("p[%zu] = %.2x\n", i, p[i]);
+               }
+       }
+       return t_status;
+}