From: David van Moolenbroek Date: Sun, 1 Nov 2009 22:25:54 +0000 (+0000) Subject: ash: only execute regular files X-Git-Tag: v3.1.6~227 X-Git-Url: http://zhaoyanbai.com/repos/doc/zlib_tech.html?a=commitdiff_plain;h=769bed22c85aff4ae34549a9be0c0ee9e68b81fb;p=minix.git ash: only execute regular files --- diff --git a/commands/ash/input.c b/commands/ash/input.c index 109cbfa30..5d531dbaa 100755 --- a/commands/ash/input.c +++ b/commands/ash/input.c @@ -47,6 +47,7 @@ __FBSDID("$FreeBSD: src/bin/sh/input.c,v 1.22 2004/04/06 20:06:51 markm Exp $"); #include #include #include +#include /* * This file implements the input routines used by the parser. @@ -430,10 +431,21 @@ setinputfile(char *fname, int push) { int fd; int fd2; + struct stat statbuf; + int saved_errno; INTOFF; if ((fd = open(fname, O_RDONLY)) < 0) error("Can't open %s: %s", fname, strerror(errno)); + if (fstat(fd, &statbuf) < 0) { + saved_errno = errno; + close(fd); + error("Can't stat %s: %s", fname, strerror(saved_errno)); + } + if (!S_ISREG(statbuf.st_mode)) { + close(fd); + error("Can't open %s: %s", fname, strerror(ENOEXEC)); + } if (fd < 10) { fd2 = fcntl(fd, F_DUPFD, 10); close(fd);