From f280b66d0a36bebabb6fad802d5214d4dc7e53c6 Mon Sep 17 00:00:00 2001 From: tg Date: Fri, 15 Jun 2007 21:22:40 +0000 Subject: [PATCH] make sure ELF, a.out, COFF, MZ/PE and gzip binaries aren't executed via sh should save us some error messages --- exec.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/exec.c b/exec.c index ae5e4de..171e100 100644 --- a/exec.c +++ b/exec.c @@ -2,7 +2,7 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/exec.c,v 1.32 2007/06/06 23:28:14 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/exec.c,v 1.33 2007/06/15 21:22:40 tg Exp $"); static int comexec(struct op *, struct tbl *volatile, const char **, int volatile); @@ -737,8 +737,20 @@ scriptexec(struct op *tp, const char **ap) if (*cp) *tp->args-- = (char *)cp; } - } noshebang: + fd = buf[0] << 8 | buf[1]; + if ((fd == /* OMAGIC */ 0407) || + (fd == /* NMAGIC */ 0410) || + (fd == /* ZMAGIC */ 0413) || + (fd == /* QMAGIC */ 0314) || + (fd == /* ECOFF_I386 */ 0x4C01) || + (fd == /* ECOFF_M68K */ 0x0150 || fd == 0x5001) || + (fd == /* ECOFF_SH */ 0x0500 || fd == 0x0005) || + (fd == 0x7F45 && buf[2] == 'L' && buf[3] == 'F') || + (fd == /* “MZ” */ 0x4D5A) || + (fd == /* gzip */ 0x1F8B)) + errorf("%s: not executable: magic %04X", tp->str, fd); + } #endif args.ro = tp->args; *args.ro = sh;