don't get confused by ifcs created by the clone device but with no associated device. also don't corrupt memory if parsing goes wrong. example: minooka; cat /net/ipifc/1/status device maxtu 0 sendra 0 recvra 0 mflag 0 oflag 0 maxraint 0 minraint 0 linkmtu 0 reachtime 0 rxmitra 0 ttl 0 routerlt 0 pktin 0 pktout 0 errin 0 errout 0 minooka; ipifc 0:/net/ether0 00304861c89e 1514 205.185.197.113/120 205.185.197.0 1:maxtu 0 0:/net.alt/ether1 00304861c89f 1514 65.14.39.134/123 65.14.39.128 12.51.113.6/123 12.51.113.0 0:/net.10g/ether4 0060dd4785f5 9000 205.185.197.114/120 205.185.197.0 minooka; 8.ipifc # compiled with change. 0:/net/ether0 00304861c89e 1514 205.185.197.113/120 205.185.197.0 0:/net.alt/ether1 00304861c89f 1514 65.14.39.134/123 65.14.39.128 12.51.113.6/123 12.51.113.0 0:/net.10g/ether4 0060dd4785f5 9000 205.185.197.114/120 205.185.197.0 Reference: /n/sources/patch/applied/readipifc Date: Tue Jan 29 16:54:07 CET 2008 Signed-off-by: quanstro@quanstro.net --- /sys/src/libip/readipifc.c Tue Jan 29 16:48:37 2008 +++ /sys/src/libip/readipifc.c Tue Jan 29 16:48:35 2008 @@ -61,7 +61,7 @@ char buf[4*1024]; char *line[32]; char *f[64]; - Ipifc *ifc; + Ipifc *ifc, **l0; Iplifc *lifc, **ll; /* read the file */ @@ -76,11 +76,14 @@ if(strncmp(buf, "device", 6) != 0) return _readoldipifc(buf, l, index); - + /* ignore ifcs with no associated device */ + if(strncmp(buf+6, " ", 2) == 0) + return l; /* allocate new interface */ *l = ifc = mallocz(sizeof(Ipifc), 1); if(ifc == nil) return l; + l0 = l; l = &ifc->next; ifc->index = index; @@ -88,10 +91,14 @@ /* pick off device specific info(first line) */ n = tokenize(line[0], f, nelem(f)); + if(n%2) + goto lose; strncpy(ifc->dev, findfield("device", f, n), sizeof(ifc->dev)); ifc->dev[sizeof(ifc->dev)-1] = 0; if(ifc->dev[0] == 0){ +lose: free(ifc); + *l0 = nil; return l; } ifc->mtu = strtoul(findfield("maxtu", f, n), nil, 10);