ref: 1e0b65c8bfb2f1b6fbc189795b73a6e89b05dc75
parent: d843bc8e22a7db269867fdc702bd0043e4f499a0
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Sun Dec 23 17:43:29 EST 2018
dossrv: make GLONG() return ulong, handle getsect() error in dostat()
--- a/sys/src/cmd/dossrv/dat.h
+++ b/sys/src/cmd/dossrv/dat.h
@@ -172,8 +172,8 @@
DARCH = 0x20,
};
-#define GSHORT(p) (((p)[0])|(p)[1]<<8)
-#define GLONG(p) (((long)(p)[0])|(p)[1]<<8|(p)[2]<<16|(p)[3]<<24)
+#define GSHORT(p) (((ushort)(p)[0])|(ushort)(p)[1]<<8)
+#define GLONG(p) (((ulong)(p)[0])|(ulong)(p)[1]<<8|(ulong)(p)[2]<<16|(ulong)(p)[3]<<24)
#define PSHORT(p,v) ((p)[0]=(v),(p)[1]=(v)>>8)
#define PLONG(p,v) ((p)[0]=(v),(p)[1]=(v)>>8,(p)[2]=(v)>>16,(p)[3]=(v)>>24)
--- a/sys/src/cmd/dossrv/dosfs.c
+++ b/sys/src/cmd/dossrv/dosfs.c
@@ -631,7 +631,7 @@
sync();
}
-static void
+static int
dostat(Xfile *f, Dir *d)
{
Dosptr *dp;
@@ -663,6 +663,8 @@
}
if(prevdo < 0 && dp->prevaddr != -1){
p = getsect(f->xf, dp->prevaddr);
+ if(p == nil)
+ return -1;
for(prevdo = ((Dosbpb*)f->xf->ptr)->sectsize-DOSDIRSIZE; prevdo >= 0; prevdo -= DOSDIRSIZE){
if(p->iobuf[prevdo+11] != 0xf)
break;
@@ -674,6 +676,7 @@
if(islong && sum == -1 && nameok(namebuf))
strcpy(d->name, namebuf);
}
+ return 0;
}
void
@@ -687,12 +690,13 @@
errno = Eio;
return;
}
-
dir.name = repdata;
- dostat(f, &dir);
-
- rep->nstat = convD2M(&dir, statbuf, sizeof statbuf);
- rep->stat = statbuf;
+ if(dostat(f, &dir) < 0)
+ errno = Eio;
+ else {
+ rep->nstat = convD2M(&dir, statbuf, sizeof statbuf);
+ rep->stat = statbuf;
+ }
putfile(f);
}
@@ -724,7 +728,11 @@
changes = 0;
dir.name = repdata;
- dostat(f, &dir);
+ if(dostat(f, &dir) < 0){
+ errno = Eio;
+ goto out;
+ }
+
if(convM2D(req->stat, req->nstat, &wdir, (char*)statbuf) != req->nstat){
errno = Ebadstat;
goto out;
--- a/sys/src/cmd/dossrv/dossubs.c
+++ b/sys/src/cmd/dossrv/dossubs.c
@@ -73,7 +73,7 @@
}
p = getsect(xf, 0);
- if(p == 0)
+ if(p == nil)
return -1;
b = (Dosboot*)p->iobuf;
@@ -547,7 +547,7 @@
if(addr < 0)
break;
p = getsect(xf, addr);
- if(p == 0)
+ if(p == nil)
break;
for(o=0; o<bp->sectsize; o+=DOSDIRSIZE){
d = (Dosdir *)&p->iobuf[o];
@@ -653,7 +653,7 @@
if(addr < 0)
break;
p = getsect(xf, addr);
- if(p == 0)
+ if(p == nil)
return -1;
for(o=0; o<bp->sectsize; o+=DOSDIRSIZE){
d = (Dosdir *)&p->iobuf[o];
@@ -703,7 +703,7 @@
if(addr < 0)
break;
p = getsect(xf, addr);
- if(p == 0)
+ if(p == nil)
return -1;
for(o=0; o<bp->sectsize; o+=DOSDIRSIZE){
d = (Dosdir *)&p->iobuf[o];
@@ -833,7 +833,7 @@
* verify that parent's . points to itself
*/
p = getsect(f->xf, clust2sect(bp, pstart));
- if(p == 0){
+ if(p == nil){
chat("getsect %ld failed\n", pstart);
goto error;
}
@@ -907,7 +907,7 @@
}
putsect(p);
p = getsect(f->xf, k);
- if(p == 0){
+ if(p == nil){
chat("getsect %lld failed\n", k);
goto error;
}
@@ -959,7 +959,7 @@
if(c > count)
c = count;
p = getsect(xf, addr);
- if(p == 0)
+ if(p == nil)
return -1;
memmove(&buf[rcnt], &p->iobuf[o], c);
putsect(p);
@@ -1115,7 +1115,7 @@
dp->mode |= DMDIR|0111;
dp->length = 0;
}else
- dp->length = (ulong)GLONG(d->length);
+ dp->length = GLONG(d->length);
if(d->attr & DSYSTEM){
dp->mode |= DMEXCL;
if(iscontig(xfs, d))
@@ -1788,8 +1788,8 @@
Bprint(&bp, "fatsize: %d\n", GSHORT(b->fatsize));
Bprint(&bp, "trksize: %d\n", GSHORT(b->trksize));
Bprint(&bp, "nheads: %d\n", GSHORT(b->nheads));
- Bprint(&bp, "nhidden: %ld\n", GLONG(b->nhidden));
- Bprint(&bp, "bigvolsize: %ld\n", GLONG(b->bigvolsize));
+ Bprint(&bp, "nhidden: %lud\n", GLONG(b->nhidden));
+ Bprint(&bp, "bigvolsize: %lud\n", GLONG(b->bigvolsize));
Bprint(&bp, "driveno: %d\n", b->driveno);
Bprint(&bp, "reserved0: 0x%2.2x\n", b->reserved0);
Bprint(&bp, "bootsig: 0x%2.2x\n", b->bootsig);
@@ -1817,12 +1817,12 @@
Bprint(&bp, "fatsize: %d\n", GSHORT(b->fatsize));
Bprint(&bp, "trksize: %d\n", GSHORT(b->trksize));
Bprint(&bp, "nheads: %d\n", GSHORT(b->nheads));
- Bprint(&bp, "nhidden: %ld\n", GLONG(b->nhidden));
- Bprint(&bp, "bigvolsize: %ld\n", GLONG(b->bigvolsize));
- Bprint(&bp, "fatsize32: %ld\n", GLONG(b->fatsize32));
+ Bprint(&bp, "nhidden: %lud\n", GLONG(b->nhidden));
+ Bprint(&bp, "bigvolsize: %lud\n", GLONG(b->bigvolsize));
+ Bprint(&bp, "fatsize32: %lud\n", GLONG(b->fatsize32));
Bprint(&bp, "extflags: %d\n", GSHORT(b->extflags));
Bprint(&bp, "version: %d\n", GSHORT(b->version1));
- Bprint(&bp, "rootstart: %ld\n", GLONG(b->rootstart));
+ Bprint(&bp, "rootstart: %lud\n", GLONG(b->rootstart));
Bprint(&bp, "infospec: %d\n", GSHORT(b->infospec));
Bprint(&bp, "backupboot: %d\n", GSHORT(b->backupboot));
Bprint(&bp, "reserved: %d %d %d %d %d %d %d %d %d %d %d %d\n",
@@ -1919,7 +1919,7 @@
i = GSHORT(d->adate);
s = seprint(s, ebuf, " %2.2d.%2.2d.%2.2d", 80+(i>>9), (i>>5)&15, i&31);
- seprint(s, ebuf, " %d %lud", GSHORT(d->start), (ulong)GLONG(d->length));
+ seprint(s, ebuf, " %d %lud", GSHORT(d->start), GLONG(d->length));
}
chat("%s\n", buf);
}