]> git.ipfire.org Git - thirdparty/shairport-sync.git/commitdiff
Fixed dangling pointer to random state array
authorBelbo <belbo@gmx.de>
Mon, 7 Aug 2017 21:49:19 +0000 (23:49 +0200)
committerBelbo <belbo@gmx.de>
Tue, 31 Oct 2017 22:19:22 +0000 (23:19 +0100)
The C library function initstate(), at least in macOS El Capitan, not only sets the state array given to it as the second argument, but also accesses the state array given to it in a previous call! (I don't know why, or if that behaviour is correct, but macOS seems to do that anyhow).
Therefore, we cannot pass a local variable to it. As soon as the player thread stops, it will be a dangling pointer, and when a new player thread is started afterwards, initstate() will dereference that dangling pointer with unforeseeable consequences.

player.c

index c6a20d7c798c1ee21163f70fcc209540c9380bfe..92d7e575263a082231f913d80528a98142427174 100644 (file)
--- a/player.c
+++ b/player.c
@@ -1481,7 +1481,7 @@ static void *player_thread_func(void *arg) {
   // I think it's useful to keep this prime to prevent it from falling into a pattern with some
   // other process.
 
-  char rnstate[256];
+  static char rnstate[256];
   initstate(time(NULL), rnstate, 256);
 
   signed short *inbuf, *tbuf, *silence;