From 457f96b65e4f7241aceaa7cb9c7bbce7be1a2212 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Mon, 25 Jan 2021 21:22:36 +0100 Subject: 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 --- src/ipc-uapi.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src') 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; -- cgit v1.2.3-59-g8ed1b