ref: 8d2b84747b1cbc54d6f23cc461d3ef838c1dfec9
parent: 2ca3934809cc51fed6a386eb13f67f08fd89fdf2
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Fri Jan 5 01:46:35 EST 2024
ip/ppp: fix race condition with rfork() ipinprocpid is static so shared with parent and child, so we need a temporary variable on the local stack to properly assign ipinprocpid.
--- a/sys/src/cmd/ip/ppp/ppp.c
+++ b/sys/src/cmd/ip/ppp/ppp.c
@@ -1640,7 +1640,7 @@
ipopen(PPP *ppp)
{
static int ipinprocpid;
- int n, cfd, fd;
+ int n, cfd, fd, pid;
char path[128];
char buf[128];
@@ -1676,7 +1676,7 @@
close(cfd);
ppp->ipfd = fd;
- switch(ipinprocpid = rfork(RFPROC|RFMEM|RFNOWAIT)){
+ switch(pid = rfork(RFPROC|RFMEM|RFNOWAIT)){
case -1:
terminate(ppp, "forking ipinproc", 1);
case 0:
@@ -1684,6 +1684,7 @@
terminate(ppp, "ipinproc", 0);
exits(nil);
}
+ ipinprocpid = pid;
if(validv4(ppp->local)){
if(!validv4(ppp->remote))