ref: 5560efb3dbe76bfab78d0d7f97969d7589a3f171
parent: 05cd5cb200b6b585b2fa255e46745bff38e17faa
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Sat Feb 24 22:32:29 EST 2018
devip: fix crash on negative dev id on attach
--- a/sys/src/9/ip/devip.c
+++ b/sys/src/9/ip/devip.c
@@ -256,32 +256,6 @@
fmtinstall('M', eipfmt);
}
-static Fs*
-ipgetfs(int dev)
-{
- extern void (*ipprotoinit[])(Fs*);
- Fs *f;
- int i;
-
- if(dev >= Nfs)
- return nil;
-
- qlock(&fslock);
- if(ipfs[dev] == nil){
- f = smalloc(sizeof(Fs));
- ip_init(f);
- arpinit(f);
- netloginit(f);
- for(i = 0; ipprotoinit[i]; i++)
- ipprotoinit[i](f);
- f->dev = dev;
- ipfs[dev] = f;
- }
- qunlock(&fslock);
-
- return ipfs[dev];
-}
-
IPaux*
newipaux(char *owner, char *tag)
{
@@ -303,14 +277,30 @@
static Chan*
ipattach(char* spec)
{
+ ulong dev;
Chan *c;
- int dev;
- dev = atoi(spec);
+ dev = strtoul(spec, nil, 0);
if(dev >= Nfs)
- error("bad specification");
+ error(Ebadspec);
- ipgetfs(dev);
+ qlock(&fslock);
+ if(ipfs[dev] == nil){
+ extern void (*ipprotoinit[])(Fs*);
+ Fs *f;
+ int i;
+
+ f = smalloc(sizeof(Fs));
+ ip_init(f);
+ arpinit(f);
+ netloginit(f);
+ for(i = 0; ipprotoinit[i]; i++)
+ ipprotoinit[i](f);
+ f->dev = dev;
+ ipfs[dev] = f;
+ }
+ qunlock(&fslock);
+
c = devattach('I', spec);
mkqid(&c->qid, QID(0, 0, Qtopdir), 0, QTDIR);
c->dev = dev;