execve: handle null files
authorAlan Cox <alan@linux.intel.com>
Sat, 27 Dec 2014 13:59:03 +0000 (13:59 +0000)
committerAlan Cox <alan@linux.intel.com>
Sat, 27 Dec 2014 13:59:03 +0000 (13:59 +0000)
When given an empty file execve was doing a bmap and trying to load block
-1 from the disk. Catch the empty file case earlier and error it.

Kernel/syscall_exec.c

index a925790..15a1cc2 100644 (file)
@@ -55,6 +55,11 @@ int16_t _execve(void)
 
        setftime(ino, A_TIME);
 
+       if (ino->c_node.i_size == 0) {
+               udata.u_error = ENOEXEC;
+               goto nogood2;
+       }
+
        /* Read in the first block of the new program */
        buf = bread(ino->c_dev, bmap(ino, 0, 1), 0);
 
@@ -149,7 +154,7 @@ int16_t _execve(void)
        brelse(buf);
 
        c = ugetc((uint8_t *)PROGLOAD);
-       if (c != 0xC3)
+       if (c != EMAGIC)
                kprintf("Botched uput\n");
 
        /* At this point, we are committed to reading in and