summaryrefslogtreecommitdiff
path: root/src/exit
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2017-12-14 18:54:54 -0500
committerRich Felker <dalias@aerifal.cx>2017-12-14 18:54:54 -0500
commit64303156832bc555d11c181168db1e7834ac7069 (patch)
treed81f3bf82ad2a109c5439c820b7f267d69169d9d /src/exit
parent01957bed1e88b77f8271b6157c83c0d7f6be302c (diff)
downloadmusl-64303156832bc555d11c181168db1e7834ac7069.tar.gz
musl-64303156832bc555d11c181168db1e7834ac7069.tar.bz2
musl-64303156832bc555d11c181168db1e7834ac7069.tar.xz
musl-64303156832bc555d11c181168db1e7834ac7069.zip
fix data race in at_quick_exit
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.
Diffstat (limited to 'src/exit')
-rw-r--r--src/exit/at_quick_exit.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/exit/at_quick_exit.c b/src/exit/at_quick_exit.c
index 34541bad..ac28dfd9 100644
--- a/src/exit/at_quick_exit.c
+++ b/src/exit/at_quick_exit.c
@@ -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;
}