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/43639 - check that a file being read by the '....



details:   https://anonhg.NetBSD.org/src/rev/3fa8e5ef95f3
branches:  trunk
changeset: 345022:3fa8e5ef95f3
user:      kre <kre%NetBSD.org@localhost>
date:      Tue May 03 03:12:40 2016 +0000

description:
PR bin/43639 - check that a file being read by the '.' command
is a regular file, even when it is given as a full pathname.

diffstat:

 bin/sh/eval.c |  16 ++++++++++------
 1 files changed, 10 insertions(+), 6 deletions(-)

diffs (37 lines):

diff -r 351494166bd1 -r 3fa8e5ef95f3 bin/sh/eval.c
--- a/bin/sh/eval.c     Tue May 03 03:08:21 2016 +0000
+++ b/bin/sh/eval.c     Tue May 03 03:12:40 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: eval.c,v 1.120 2016/05/02 01:46:31 christos Exp $      */
+/*     $NetBSD: eval.c,v 1.121 2016/05/03 03:12:40 kre Exp $   */
 
 /*-
  * Copyright (c) 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)eval.c     8.9 (Berkeley) 6/8/95";
 #else
-__RCSID("$NetBSD: eval.c,v 1.120 2016/05/02 01:46:31 christos Exp $");
+__RCSID("$NetBSD: eval.c,v 1.121 2016/05/03 03:12:40 kre Exp $");
 #endif
 #endif /* not lint */
 
@@ -1260,10 +1260,14 @@
        struct stat statb;
 
        /* don't try this for absolute or relative paths */
-       if (strchr(basename, '/'))
-               return basename;
-
-       while ((fullname = padvance(&path, basename)) != NULL) {
+       if (strchr(basename, '/')) {
+               if (stat(basename, &statb) == 0) {
+                       if (S_ISREG(statb.st_mode))
+                               return basename;
+                       error("%s: not a regular file", basename);
+                       /* NOTREACHED */
+               }
+       } else while ((fullname = padvance(&path, basename)) != NULL) {
                if ((stat(fullname, &statb) == 0) && S_ISREG(statb.st_mode)) {
                        /*
                         * Don't bother freeing here, since it will



Home | Main Index | Thread Index | Old Index