From: Jason A. Donenfeld Date: Mon, 25 Jan 2021 20:22:36 +0000 (+0100) Subject: ipc: do not use fscanf with trailing \n X-Git-Tag: v1.0.20210223~3 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=457f96b65e4f7241aceaa7cb9c7bbce7be1a2212;p=thirdparty%2Fwireguard-tools.git 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 --- 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;