]> git.ipfire.org Git - thirdparty/wireguard-tools.git/commitdiff
ipc: do not use fscanf with trailing \n
authorJason A. Donenfeld <Jason@zx2c4.com>
Mon, 25 Jan 2021 20:22:36 +0000 (21:22 +0100)
committerJason A. Donenfeld <Jason@zx2c4.com>
Mon, 25 Jan 2021 20:22:36 +0000 (21:22 +0100)
If the stream is not closed, then this winds up hanging forever. So
remove the trailing \n\n and check manually after.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
src/ipc-uapi.h

index f464be700c0ccc605db5e90628b4cd054cf51e22..d2ba522a02d7e1c54ff905884559dd3e120fb583 100644 (file)
@@ -92,8 +92,10 @@ static int userspace_set_device(struct wgdevice *dev)
        fprintf(f, "\n");
        fflush(f);
 
-       if (fscanf(f, "errno=%d\n\n", &ret) != 1)
+       if (fscanf(f, "errno=%d", &ret) != 1)
                ret = errno ? -errno : -EPROTO;
+       if (getc(f) != '\n' || getc(f) != '\n')
+               ret = -EPROTO;
        fclose(f);
        errno = -ret;
        return ret;