Author: jilles
Date: Sat Jan  1 13:26:18 2011
New Revision: 216870
URL: http://svn.freebsd.org/changeset/base/216870

Log:
  sh: Check readonly status for assignments on regular builtins.
  
  An error message is written, the builtin is not executed, nonzero exit
  status is returned but the shell does not abort.
  
  This was already checked for special builtins and external commands, with
  the same consequences except that the shell aborts for special builtins.
  
  Obtained from:        NetBSD

Added:
  head/tools/regression/bin/sh/errors/assignment-error2.0   (contents, props 
changed)
Modified:
  head/bin/sh/eval.c
  head/bin/sh/var.c
  head/bin/sh/var.h

Modified: head/bin/sh/eval.c
==============================================================================
--- head/bin/sh/eval.c  Sat Jan  1 08:47:38 2011        (r216869)
+++ head/bin/sh/eval.c  Sat Jan  1 13:26:18 2011        (r216870)
@@ -997,8 +997,7 @@ evalcommand(union node *cmd, int flags, 
                 */
                if (argc == 0 && !(flags & EV_BACKCMD))
                        cmdentry.special = 1;
-               if (cmdentry.special)
-                       listsetvar(cmdenviron);
+               listsetvar(cmdenviron, cmdentry.special ? 0 : VNOSET);
                if (argc > 0)
                        bltinsetlocale();
                commandname = argv[0];

Modified: head/bin/sh/var.c
==============================================================================
--- head/bin/sh/var.c   Sat Jan  1 08:47:38 2011        (r216869)
+++ head/bin/sh/var.c   Sat Jan  1 13:26:18 2011        (r216870)
@@ -333,6 +333,8 @@ setvareq(char *s, int flags)
                                len = strchr(s, '=') - s;
                                error("%.*s: is read only", len, s);
                        }
+                       if (flags & VNOSET)
+                               return;
                        INTOFF;
 
                        if (vp->func && (flags & VNOFUNC) == 0)
@@ -365,6 +367,8 @@ setvareq(char *s, int flags)
                }
        }
        /* not found */
+       if (flags & VNOSET)
+               return;
        vp = ckmalloc(sizeof (*vp));
        vp->flags = flags;
        vp->text = s;
@@ -386,13 +390,13 @@ setvareq(char *s, int flags)
  */
 
 void
-listsetvar(struct strlist *list)
+listsetvar(struct strlist *list, int flags)
 {
        struct strlist *lp;
 
        INTOFF;
        for (lp = list ; lp ; lp = lp->next) {
-               setvareq(savestr(lp->text), 0);
+               setvareq(savestr(lp->text), flags);
        }
        INTON;
 }

Modified: head/bin/sh/var.h
==============================================================================
--- head/bin/sh/var.h   Sat Jan  1 08:47:38 2011        (r216869)
+++ head/bin/sh/var.h   Sat Jan  1 13:26:18 2011        (r216870)
@@ -45,6 +45,7 @@
 #define VSTACK         0x10    /* text is allocated on the stack */
 #define VUNSET         0x20    /* the variable is not set */
 #define VNOFUNC                0x40    /* don't call the callback function */
+#define VNOSET         0x80    /* do not set variable - just readonly test */
 
 
 struct var {
@@ -106,7 +107,7 @@ void initvar(void);
 void setvar(const char *, const char *, int);
 void setvareq(char *, int);
 struct strlist;
-void listsetvar(struct strlist *);
+void listsetvar(struct strlist *, int);
 char *lookupvar(const char *);
 char *bltinlookup(const char *, int);
 void bltinsetlocale(void);

Added: head/tools/regression/bin/sh/errors/assignment-error2.0
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ head/tools/regression/bin/sh/errors/assignment-error2.0     Sat Jan  1 
13:26:18 2011        (r216870)
@@ -0,0 +1,8 @@
+# $FreeBSD$
+
+set -e
+HOME=/
+readonly HOME
+cd /sbin
+{ HOME=/bin cd; } 2>/dev/null || :
+[ "$(pwd)" != /bin ]
_______________________________________________
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to