fix data race in at_quick_exit
authorRich Felker <dalias@aerifal.cx>
Thu, 14 Dec 2017 23:54:54 +0000 (18:54 -0500)
committerRich Felker <dalias@aerifal.cx>
Thu, 14 Dec 2017 23:54:54 +0000 (18:54 -0500)
aside from theoretical arbitrary results due to UB, this could
practically cause unbounded overflow of static array if hit, but
hitting it depends on having more than 32 calls to at_quick_exit and
having them sufficiently often.

src/exit/at_quick_exit.c

index 34541ba..ac28dfd 100644 (file)
@@ -21,9 +21,10 @@ void __funcs_on_quick_exit()
 
 int at_quick_exit(void (*func)(void))
 {
-       if (count == 32) return -1;
+       int r = 0;
        LOCK(lock);
-       funcs[count++] = func;
+       if (count == 32) r = -1;
+       else funcs[count++] = func;
        UNLOCK(lock);
-       return 0;
+       return r;
 }