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
This commit is contained in:
parent
d3f4786a1f
commit
b2d7992025
9 changed files with 27 additions and 33 deletions
|
@ -277,12 +277,12 @@ newipaux(char *owner, char *tag)
|
||||||
static Chan*
|
static Chan*
|
||||||
ipattach(char* spec)
|
ipattach(char* spec)
|
||||||
{
|
{
|
||||||
ulong dev;
|
|
||||||
Chan *c;
|
Chan *c;
|
||||||
|
ulong dev;
|
||||||
|
|
||||||
dev = strtoul(spec, nil, 0);
|
dev = strtoul(spec, nil, 10);
|
||||||
if(dev >= Nfs)
|
if(dev >= Nfs)
|
||||||
error(Ebadspec);
|
error(Enodev);
|
||||||
|
|
||||||
qlock(&fslock);
|
qlock(&fslock);
|
||||||
if(ipfs[dev] == nil){
|
if(ipfs[dev] == nil){
|
||||||
|
|
|
@ -90,7 +90,7 @@ static Chan*
|
||||||
vgaattach(char* spec)
|
vgaattach(char* spec)
|
||||||
{
|
{
|
||||||
if(*spec && strcmp(spec, "0"))
|
if(*spec && strcmp(spec, "0"))
|
||||||
error(Eio);
|
error(Enodev);
|
||||||
return devattach('v', spec);
|
return devattach('v', spec);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -120,16 +120,13 @@ audioclone(Chan *c, Audio *adev)
|
||||||
static Chan*
|
static Chan*
|
||||||
audioattach(char *spec)
|
audioattach(char *spec)
|
||||||
{
|
{
|
||||||
static int attached = 0;
|
static ulong attached = 0;
|
||||||
Audiochan *ac;
|
Audiochan *ac;
|
||||||
Audio *adev;
|
Audio *adev;
|
||||||
Chan *c;
|
Chan *c;
|
||||||
int i;
|
ulong i;
|
||||||
|
|
||||||
if(spec != nil && *spec != '\0')
|
i = strtoul(spec, nil, 10);
|
||||||
i = strtol(spec, 0, 10);
|
|
||||||
else
|
|
||||||
i = 0;
|
|
||||||
for(adev = audiodevs; adev; adev = adev->next)
|
for(adev = audiodevs; adev; adev = adev->next)
|
||||||
if(adev->ctlrno == i)
|
if(adev->ctlrno == i)
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -193,14 +193,14 @@ bridgeinit(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
static Chan*
|
static Chan*
|
||||||
bridgeattach(char* spec)
|
bridgeattach(char *spec)
|
||||||
{
|
{
|
||||||
Chan *c;
|
Chan *c;
|
||||||
int dev;
|
ulong dev;
|
||||||
|
|
||||||
dev = atoi(spec);
|
dev = strtoul(spec, nil, 10);
|
||||||
if(dev<0 || dev >= Maxbridge)
|
if(dev >= Maxbridge)
|
||||||
error("bad specification");
|
error(Enodev);
|
||||||
|
|
||||||
c = devattach('B', spec);
|
c = devattach('B', spec);
|
||||||
mkqid(&c->qid, QID(0, Qtopdir), 0, QTDIR);
|
mkqid(&c->qid, QID(0, Qtopdir), 0, QTDIR);
|
||||||
|
|
|
@ -25,7 +25,7 @@ etherattach(char* spec)
|
||||||
|
|
||||||
ctlrno = 0;
|
ctlrno = 0;
|
||||||
if(*spec){
|
if(*spec){
|
||||||
ctlrno = strtoul(spec, &conf, 0);
|
ctlrno = strtoul(spec, &conf, 10);
|
||||||
if(ctlrno >= MaxEther)
|
if(ctlrno >= MaxEther)
|
||||||
error(Enodev);
|
error(Enodev);
|
||||||
if(conf == spec)
|
if(conf == spec)
|
||||||
|
|
|
@ -167,11 +167,11 @@ static Chan*
|
||||||
flashattach(char *spec)
|
flashattach(char *spec)
|
||||||
{
|
{
|
||||||
Flash *f;
|
Flash *f;
|
||||||
int bank;
|
|
||||||
Chan *c;
|
Chan *c;
|
||||||
|
ulong bank;
|
||||||
|
|
||||||
bank = strtol(spec, nil, 0);
|
bank = strtoul(spec, nil, 10);
|
||||||
if(bank < 0 || bank >= Nbanks ||
|
if(bank >= Nbanks ||
|
||||||
(f = flash.card[bank]) == nil ||
|
(f = flash.card[bank]) == nil ||
|
||||||
f->attach != nil && f->attach(f) < 0)
|
f->attach != nil && f->attach(f) < 0)
|
||||||
error(Enodev);
|
error(Enodev);
|
||||||
|
|
|
@ -121,14 +121,11 @@ loopbackattach(char *spec)
|
||||||
Queue *q;
|
Queue *q;
|
||||||
Chan *c;
|
Chan *c;
|
||||||
int chan;
|
int chan;
|
||||||
int dev;
|
ulong dev;
|
||||||
|
|
||||||
dev = 0;
|
dev = strtoul(spec, nil, 10);
|
||||||
if(spec != nil){
|
if(dev >= Nloopbacks)
|
||||||
dev = atoi(spec);
|
error(Enodev);
|
||||||
if(dev >= Nloopbacks)
|
|
||||||
error(Ebadspec);
|
|
||||||
}
|
|
||||||
|
|
||||||
c = devattach('X', spec);
|
c = devattach('X', spec);
|
||||||
if(waserror()){
|
if(waserror()){
|
||||||
|
|
|
@ -662,8 +662,8 @@ sdattach(char* spec)
|
||||||
if(spec[0] != 's' || spec[1] != 'd')
|
if(spec[0] != 's' || spec[1] != 'd')
|
||||||
error(Ebadspec);
|
error(Ebadspec);
|
||||||
idno = spec[2];
|
idno = spec[2];
|
||||||
subno = strtol(&spec[3], &p, 0);
|
subno = strtol(&spec[3], &p, 10);
|
||||||
if(p == &spec[3])
|
if(subno < 0 || p == &spec[3])
|
||||||
error(Ebadspec);
|
error(Ebadspec);
|
||||||
|
|
||||||
if((sdev=sdgetdev(idno)) == nil)
|
if((sdev=sdgetdev(idno)) == nil)
|
||||||
|
|
|
@ -364,14 +364,14 @@ static Chan*
|
||||||
sdpattach(char* spec)
|
sdpattach(char* spec)
|
||||||
{
|
{
|
||||||
Chan *c;
|
Chan *c;
|
||||||
int dev;
|
|
||||||
char buf[100];
|
char buf[100];
|
||||||
Sdp *sdp;
|
Sdp *sdp;
|
||||||
int start;
|
int start;
|
||||||
|
ulong dev;
|
||||||
|
|
||||||
dev = atoi(spec);
|
dev = strtoul(spec, nil, 10);
|
||||||
if(dev<0 || dev >= Nfs)
|
if(dev >= Nfs)
|
||||||
error("bad specification");
|
error(Enodev);
|
||||||
|
|
||||||
c = devattach('E', spec);
|
c = devattach('E', spec);
|
||||||
c->qid = (Qid){QID(0, Qtopdir), 0, QTDIR};
|
c->qid = (Qid){QID(0, Qtopdir), 0, QTDIR};
|
||||||
|
@ -384,7 +384,7 @@ sdpattach(char* spec)
|
||||||
qunlock(sdp);
|
qunlock(sdp);
|
||||||
|
|
||||||
if(start) {
|
if(start) {
|
||||||
snprint(buf, sizeof(buf), "sdpackproc%d", dev);
|
snprint(buf, sizeof(buf), "sdpackproc%lud", dev);
|
||||||
kproc(buf, sdpackproc, sdp);
|
kproc(buf, sdpackproc, sdp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue