Remove unnecessary panic() in rread()
authorBarret Rhoden <brho@cs.berkeley.edu>
Wed, 3 Apr 2019 03:34:33 +0000 (23:34 -0400)
committerBarret Rhoden <brho@cs.berkeley.edu>
Wed, 3 Apr 2019 03:34:33 +0000 (23:34 -0400)
Ultimately, we throw an error when attempting to do a short read on a
directory.

Reported-by: syzbot+fbc1784c73dfdf878652@syzkaller.appspotmail.com
Signed-off-by: Barret Rhoden <brho@cs.berkeley.edu>
kern/src/ns/sysfile.c

index 8ea6680..557f3ef 100644 (file)
@@ -725,8 +725,10 @@ static long rread(int fd, void *va, long n, int64_t * offp)
         */
        if (dir) {
                int amt;
-               /* expecting only one dirent at a time, o/w we're busted */
-               assert(n >= sizeof(struct kdirent));
+
+               if (n < sizeof(struct kdirent))
+                       error(EINVAL, "readdir needs to read at least %d",
+                             sizeof(struct kdirent));
                if (!c->buf) {
                        c->buf = kmalloc(DIRREADSIZE, MEM_WAIT);
                        c->bufused = 0;