make sure ELF, a.out, COFF, MZ/PE and gzip binaries aren't executed via sh

should save us some error messages
This commit is contained in:
tg 2007-06-15 21:22:40 +00:00
parent 1b16db54f1
commit f280b66d0a
1 changed files with 14 additions and 2 deletions

16
exec.c
View File

@ -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;