9front - general discussion about 9front
 help / color / mirror / Atom feed
From: ori@eigenstate.org
To: 9front@9front.org
Subject: dossrv: Some error checking.
Date: Sun, 5 Apr 2020 17:48:52 -0700	[thread overview]
Message-ID: <D3D071707A5041DD5C01454A09652AFD@eigenstate.org> (raw)

This change adds some missing checks to dossrv. There
were a few places where we didn't check the return value
of getsect and getosect. This should catch all of them
and propagate the error upwards. I tested this lightly,
but the only fat partitions I have are the 9fat partions
I use for booting -- so if there are any heavy dossrv users,
I'd appreciate reports.

This came up last night when debugging sl's issues
when writing to large disks using dossrv.

diff -r ed9a8f50c08f sys/src/cmd/dossrv/dosfs.c
--- a/sys/src/cmd/dossrv/dosfs.c	Sun Apr 05 03:46:47 2020 +0200
+++ b/sys/src/cmd/dossrv/dosfs.c	Sun Apr 05 17:44:54 2020 -0700
@@ -550,7 +550,7 @@
 /*
  * wipe out a dos directory entry
  */
-static void
+static int
 doremove(Xfs *xf, Dosptr *dp)
 {
 	Iosect *p;
@@ -565,6 +565,8 @@
 	}
 	if(prevdo < 0 && dp->prevaddr != -1){
 		p = getsect(xf, dp->prevaddr);
+		if(p == nil)
+			return -1;
 		for(prevdo = ((Dosbpb*)xf->ptr)->sectsize-DOSDIRSIZE; prevdo >= 0; prevdo -= DOSDIRSIZE){
 			if(p->iobuf[prevdo+11] != 0xf)
 				break;
@@ -572,7 +574,8 @@
 			p->flags |= BMOD;
 		}
 		putsect(p);
-	}		
+	}
+	return 0;		
 }
 
 void
@@ -601,8 +604,7 @@
 	 * or it's a read only file in the root directory
 	 */
 	parp = getsect(f->xf, dp->paddr);
-	if(parp == nil
-	|| getfile(f) < 0){
+	if(parp == nil || getfile(f) < 0){
 		errno = Eio;
 		goto out;
 	}
@@ -617,7 +619,10 @@
 		errno = Eio;
 		goto out;
 	}
-	doremove(f->xf, f->ptr);
+	if(doremove(f->xf, f->ptr) == -1){
+		errno = Eio;
+		goto out;
+	}
 	if(!isroot(dp->paddr)){
 		puttime(pard, 0);
 		parp->flags |= BMOD;
diff -r ed9a8f50c08f sys/src/cmd/dossrv/dossubs.c
--- a/sys/src/cmd/dossrv/dossubs.c	Sun Apr 05 03:46:47 2020 +0200
+++ b/sys/src/cmd/dossrv/dossubs.c	Sun Apr 05 17:44:54 2020 -0700
@@ -1000,6 +1000,8 @@
 			c = count;
 		if(c == bp->sectsize){
 			p = getosect(xf, addr);
+			if(p == nil)
+				return -1;
 			p->flags = 0;
 		}else{
 			p = getsect(xf, addr);
@@ -1632,7 +1634,8 @@
 			if(rp == nil)
 				return -1;
 			wp = getosect(xf, ws);
-			assert(wp != nil);
+			if(wp == nil)
+				return -1;
 			memmove(wp->iobuf, rp->iobuf, bp->sectsize);
 			wp->flags = BMOD;
 			putsect(rp);
@@ -1683,8 +1686,7 @@
 {
 	Dosbpb *bp = xf->ptr;
 	Iosect *p;
-	int n, i;
-	vlong k;
+	int n, i, k;
 
 	n = bp->freeptr;
 	for(;;){
@@ -1702,6 +1704,8 @@
 	k = clust2sect(bp, n);
 	for(i=0; i<bp->clustsize; i++){
 		p = getosect(xf, k+i);
+		if(p == nil)
+			return -1;
 		memset(p->iobuf, 0, bp->sectsize);
 		p->flags = BMOD;
 		putsect(p);
diff -r ed9a8f50c08f sys/src/cmd/dossrv/iotrack.c
--- a/sys/src/cmd/dossrv/iotrack.c	Sun Apr 05 03:46:47 2020 +0200
+++ b/sys/src/cmd/dossrv/iotrack.c	Sun Apr 05 17:44:54 2020 -0700
@@ -39,8 +39,10 @@
 	int toff;
 	Iosect *p;
 
-	if(addr < 0)
+	if(addr < 0){
+		werrstr("invalid address");
 		return nil;
+	}
 	toff = addr % Sect2trk;
 	taddr = addr - toff;
 	t = getiotrack(xf, taddr);
@@ -53,8 +55,10 @@
 	}
 	t->ref++;
 	p = t->tp->p[toff];
-	if(p == 0){
+	if(p == nil){
 		p = newsect();
+		if(p == nil)
+			return nil;
 		t->tp->p[toff] = p;
 		p->flags = t->flags&BSTALE;
 		p->lock.key = 0;
@@ -196,10 +200,10 @@
 			t->flags &= ~BSTALE;
 	}
 	if(devwrite(t->xf, t->addr, t->tp->buf, Trksize) < 0){
-		chat("error]");
+		chat("error]\n");
 		return -1;
 	}
-	chat(" done]");
+	chat(" done]\n");
 	return 0;
 }
 
@@ -304,6 +308,8 @@
 	else
 		p = malloc(sizeof(Iosect));
 	unmlock(&freelock);
+	if(p == nil)
+		return nil;
 	p->next = 0;
 	return p;
 }



             reply	other threads:[~2020-04-06  0:48 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-06  0:48 ori [this message]
2020-04-06  1:27 ` [9front] " Alex Musolino
2020-04-06  1:39   ` ori
2020-04-06  2:02   ` ori

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=D3D071707A5041DD5C01454A09652AFD@eigenstate.org \
    --to=ori@eigenstate.org \
    --cc=9front@9front.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).