kernel: properly handle bad attach specifiers

- only accept decimal for numeric device id's
- exclude negative device id's
- device id's out of range yield Enodev
front
cinap_lenrek 2018-02-25 17:11:18 +01:00
parent d3f4786a1f
commit b2d7992025
9 changed files with 27 additions and 33 deletions

View File

@ -277,12 +277,12 @@ newipaux(char *owner, char *tag)
static Chan*
ipattach(char* spec)
{
ulong dev;
Chan *c;
ulong dev;
dev = strtoul(spec, nil, 0);
dev = strtoul(spec, nil, 10);
if(dev >= Nfs)
error(Ebadspec);
error(Enodev);
qlock(&fslock);
if(ipfs[dev] == nil){

View File

@ -90,7 +90,7 @@ static Chan*
vgaattach(char* spec)
{
if(*spec && strcmp(spec, "0"))
error(Eio);
error(Enodev);
return devattach('v', spec);
}

View File

@ -120,16 +120,13 @@ audioclone(Chan *c, Audio *adev)
static Chan*
audioattach(char *spec)
{
static int attached = 0;
static ulong attached = 0;
Audiochan *ac;
Audio *adev;
Chan *c;
int i;
ulong i;
if(spec != nil && *spec != '\0')
i = strtol(spec, 0, 10);
else
i = 0;
i = strtoul(spec, nil, 10);
for(adev = audiodevs; adev; adev = adev->next)
if(adev->ctlrno == i)
break;

View File

@ -193,14 +193,14 @@ bridgeinit(void)
}
static Chan*
bridgeattach(char* spec)
bridgeattach(char *spec)
{
Chan *c;
int dev;
ulong dev;
dev = atoi(spec);
if(dev<0 || dev >= Maxbridge)
error("bad specification");
dev = strtoul(spec, nil, 10);
if(dev >= Maxbridge)
error(Enodev);
c = devattach('B', spec);
mkqid(&c->qid, QID(0, Qtopdir), 0, QTDIR);

View File

@ -25,7 +25,7 @@ etherattach(char* spec)
ctlrno = 0;
if(*spec){
ctlrno = strtoul(spec, &conf, 0);
ctlrno = strtoul(spec, &conf, 10);
if(ctlrno >= MaxEther)
error(Enodev);
if(conf == spec)

View File

@ -167,11 +167,11 @@ static Chan*
flashattach(char *spec)
{
Flash *f;
int bank;
Chan *c;
ulong bank;
bank = strtol(spec, nil, 0);
if(bank < 0 || bank >= Nbanks ||
bank = strtoul(spec, nil, 10);
if(bank >= Nbanks ||
(f = flash.card[bank]) == nil ||
f->attach != nil && f->attach(f) < 0)
error(Enodev);

View File

@ -121,14 +121,11 @@ loopbackattach(char *spec)
Queue *q;
Chan *c;
int chan;
int dev;
ulong dev;
dev = 0;
if(spec != nil){
dev = atoi(spec);
if(dev >= Nloopbacks)
error(Ebadspec);
}
dev = strtoul(spec, nil, 10);
if(dev >= Nloopbacks)
error(Enodev);
c = devattach('X', spec);
if(waserror()){

View File

@ -662,8 +662,8 @@ sdattach(char* spec)
if(spec[0] != 's' || spec[1] != 'd')
error(Ebadspec);
idno = spec[2];
subno = strtol(&spec[3], &p, 0);
if(p == &spec[3])
subno = strtol(&spec[3], &p, 10);
if(subno < 0 || p == &spec[3])
error(Ebadspec);
if((sdev=sdgetdev(idno)) == nil)

View File

@ -364,14 +364,14 @@ static Chan*
sdpattach(char* spec)
{
Chan *c;
int dev;
char buf[100];
Sdp *sdp;
int start;
ulong dev;
dev = atoi(spec);
if(dev<0 || dev >= Nfs)
error("bad specification");
dev = strtoul(spec, nil, 10);
if(dev >= Nfs)
error(Enodev);
c = devattach('E', spec);
c->qid = (Qid){QID(0, Qtopdir), 0, QTDIR};
@ -384,7 +384,7 @@ sdpattach(char* spec)
qunlock(sdp);
if(start) {
snprint(buf, sizeof(buf), "sdpackproc%d", dev);
snprint(buf, sizeof(buf), "sdpackproc%lud", dev);
kproc(buf, sdpackproc, sdp);
}