about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2017-08-29 19:39:03 -0400
committerRich Felker <dalias@aerifal.cx>2017-08-29 19:39:03 -0400
commit670d6d01f53b4e85be6b333bf8a137e2be6d3fc3 (patch)
treef3bf02ed4ecc831b33d857bb8f9b9875f3c0f20f
parent511b7042b3844b42a940f1c31436fb04ce93ac19 (diff)
downloadmusl-670d6d01f53b4e85be6b333bf8a137e2be6d3fc3.tar.gz
musl-670d6d01f53b4e85be6b333bf8a137e2be6d3fc3.tar.xz
musl-670d6d01f53b4e85be6b333bf8a137e2be6d3fc3.zip
fix unsynchronized access to FILE structure in fflush(0)
commit c002668eb0352e619ea7064e4940b397b4a6e68d inadvertently moved
the check for unflushed write buffer outside of the scope of the
existing lock.
-rw-r--r--src/stdio/fflush.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/stdio/fflush.c b/src/stdio/fflush.c
index c2881065..bf1e8437 100644
--- a/src/stdio/fflush.c
+++ b/src/stdio/fflush.c
@@ -9,8 +9,11 @@ int fflush(FILE *f)
 	if (!f) {
 		int r = __stdout_used ? fflush(__stdout_used) : 0;
 
-		for (f=*__ofl_lock(); f; f=f->next)
+		for (f=*__ofl_lock(); f; f=f->next) {
+			FLOCK(f);
 			if (f->wpos > f->wbase) r |= fflush(f);
+			FUNLOCK(f);
+		}
 		__ofl_unlock();
 
 		return r;