Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/bin/sh PR bin/51207 Only check for ELF bnaries in regular ...



details:   https://anonhg.NetBSD.org/src/rev/afd5393e5f8a
branches:  trunk
changeset: 345581:afd5393e5f8a
user:      kre <kre%NetBSD.org@localhost>
date:      Wed Jun 01 05:11:52 2016 +0000

description:
PR bin/51207   Only check for ELF bnaries in regular files.

diffstat:

 bin/sh/input.c |  9 ++++++---
 1 files changed, 6 insertions(+), 3 deletions(-)

diffs (44 lines):

diff -r 0ac114698d09 -r afd5393e5f8a bin/sh/input.c
--- a/bin/sh/input.c    Wed Jun 01 05:10:41 2016 +0000
+++ b/bin/sh/input.c    Wed Jun 01 05:11:52 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: input.c,v 1.50 2016/05/07 20:06:30 kre Exp $   */
+/*     $NetBSD: input.c,v 1.51 2016/06/01 05:11:52 kre Exp $   */
 
 /*-
  * Copyright (c) 1991, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)input.c    8.3 (Berkeley) 6/9/95";
 #else
-__RCSID("$NetBSD: input.c,v 1.50 2016/05/07 20:06:30 kre Exp $");
+__RCSID("$NetBSD: input.c,v 1.51 2016/06/01 05:11:52 kre Exp $");
 #endif
 #endif /* not lint */
 
@@ -48,6 +48,7 @@
 #include <limits.h>
 #include <stdlib.h>
 #include <string.h>
+#include <sys/stat.h>
 
 /*
  * This file implements the input routines used by the parser.
@@ -392,6 +393,7 @@
        unsigned char magic[4];
        int fd;
        int fd2;
+       struct stat sb;
 
        INTOFF;
        if ((fd = open(fname, O_RDONLY)) < 0)
@@ -402,7 +404,8 @@
         * avoid that message. The first lseek tries to make sure that
         * we can later rewind the file.
         */
-       if (lseek(fd, 0, SEEK_SET) == 0) {
+       if (fstat(fd, &sb) == 0 && S_ISREG(sb.st_mode) &&
+           lseek(fd, 0, SEEK_SET) == 0) {
                if (read(fd, magic, 4) == 4) {
                        if (memcmp(magic, "\177ELF", 4) == 0) {
                                (void)close(fd);



Home | Main Index | Thread Index | Old Index