diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2021-01-25 21:22:36 +0100 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2021-01-25 21:22:36 +0100 |
commit | 457f96b65e4f7241aceaa7cb9c7bbce7be1a2212 (patch) | |
tree | fd31c75511840023621f7324676a911d4f652a62 /src/ipc-uapi.h | |
parent | sticky-sockets: do not use SO_REUSEADDR (diff) | |
download | wireguard-tools-457f96b65e4f7241aceaa7cb9c7bbce7be1a2212.tar.xz wireguard-tools-457f96b65e4f7241aceaa7cb9c7bbce7be1a2212.zip |
ipc: do not use fscanf with trailing \n
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>
Diffstat (limited to 'src/ipc-uapi.h')
-rw-r--r-- | src/ipc-uapi.h | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/src/ipc-uapi.h b/src/ipc-uapi.h index f464be7..d2ba522 100644 --- a/src/ipc-uapi.h +++ b/src/ipc-uapi.h @@ -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; |