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>
This commit is contained in:
Jason A. Donenfeld 2021-01-25 21:22:36 +01:00
parent 66ed611bd0
commit 457f96b65e
1 changed files with 3 additions and 1 deletions

View 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;