From bf4d70f439c82d5e88fed3c08822166df87aff47 Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Sat, 27 Dec 2014 13:59:03 +0000 Subject: [PATCH] execve: handle null files 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 | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Kernel/syscall_exec.c b/Kernel/syscall_exec.c index a9257903..15a1cc2e 100644 --- a/Kernel/syscall_exec.c +++ b/Kernel/syscall_exec.c @@ -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 -- 2.34.1