From 769bed22c85aff4ae34549a9be0c0ee9e68b81fb Mon Sep 17 00:00:00 2001 From: David van Moolenbroek Date: Sun, 1 Nov 2009 22:25:54 +0000 Subject: [PATCH] ash: only execute regular files --- commands/ash/input.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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);