]> git.ipfire.org Git - thirdparty/bash.git/commitdiff
fix cd when user assigns a value to OLDPWD; fix android issue with blocked system...
authorChet Ramey <chet.ramey@case.edu>
Mon, 10 Jul 2023 13:41:30 +0000 (09:41 -0400)
committerChet Ramey <chet.ramey@case.edu>
Mon, 10 Jul 2023 13:41:30 +0000 (09:41 -0400)
17 files changed:
CWRU/CWRU.chlog
MANIFEST
builtins/cd.def
doc/bash.0
doc/bash.1
doc/bash.html
doc/bash.info
doc/bashref.info
doc/bashref.texi
doc/version.texi
examples/scripts/secure-script [new file with mode: 0644]
jobs.c
shell.c
shell.h
test.c
tests/test.right
tests/varenv2.sub

index 1201be94306e2c97794dfedbc39617aa6c86e820..5ad32a9de893354f55568a2c9c844fb1ba85bab1 100644 (file)
@@ -7075,3 +7075,52 @@ lib/readline/complete.c
          From a report and patch by Grisha Levit <grishalevit@gmail.com>
          back in May
 
+                                   7/6
+                                   ---
+builtins/cd.def
+       - cd_builtin: if $OLDPWD is set by the user or script to something
+         that's not a full pathname, allow it to use $CDPATH.
+         From a report by Dustin Boyd <chronokitsune3233@gmail.com>
+
+                                   7/7
+                                   ---
+shell.h
+       - user_info: add members for saved uid and saved gid
+
+shell.c
+       - uidget: if we have setresuid/setresgid, get the saved uid and saved
+         gid so we can set them if we disable privileged mode
+       - disable_priv_mode: only call setuid/setresuid and setgid/setresgid
+         if the euid (egid) != uid (gid). If we have setresuid/setresgid,
+         add a check whether the saved uid (gid) isn't the same as the real
+         uid (gid). Potentially saves a couple of system calls.
+         Fixes Android issue, patch by Grisha Levit <grishalevit@gmail.com>
+
+test.c
+       - unary_operator: only support historical handling of -t and its
+         optional argument when not in posix mode
+       - unary_test: print an error if the argument to -t is not a number
+       - unary_operator: only make the argument to -t optional if the
+         next argument is -a or -o and we are using the historical algorithm
+         (argc >= 5), otherwise force it to be a number and print an error
+         message if it's not
+         From a report by Stephane Chazelas <stephane@chazelas.org>
+
+doc/bash.1,doc/bashref.texi
+       - added note about test/[ sorting using the current locale with the
+         `<' and `>' operators when in posix mode
+       - added note about the integer argument to test -t being required
+         when in posix mode
+       - added note recommending against the use of test with 5 or more
+         arguments in favor of combining multiple instances of test with
+         && or ||
+         From a report by Stephane Chazelas <stephane@chazelas.org>
+
+                                  7/10
+                                  ----
+jobs.c
+       - start_job: turn off (on) the J_ASYNC flag depending on whether the
+         job is being started in the foreground (background). It matters now
+         that we use IS_ASYNC to determine whether to give the terminal
+         back to the shell's process group.
+         From a report by Grisha Levit <grishalevit@gmail.com>
index d1a937cd7347b808f239823fabd8ec0c7839e3c7..36ef4d413236fc77a7338c75d646da0276f06b56 100644 (file)
--- a/MANIFEST
+++ b/MANIFEST
@@ -849,6 +849,7 @@ examples/scripts/inpath             f
 #examples/scripts/scrollbar2   f
 #examples/scripts/self-repro   f
 #examples/scripts/showperm.bash        f
+examples/scripts/secure-script f
 examples/scripts/shprompt      f
 examples/scripts/spin.bash     f
 #examples/scripts/timeout      f
index e31564638fe83b9de85d655219f1b790dea44959..c9d58e56134f3faf33941149dfabddcf5bbaee8f 100644 (file)
@@ -314,9 +314,9 @@ cd_builtin (WORD_LIST *list)
   if (list == 0)
     {
       /* `cd' without arguments is equivalent to `cd $HOME' */
-      dirname = get_string_value ("HOME");
+      dirname = get_string_value ("HOME");     /* POSIX cd step 2 */
 
-      if (dirname == 0)
+      if (dirname == 0)                        /* POSIX cd step 1 */
        {
          builtin_error (_("HOME not set"));
          return (EXECUTION_FAILURE);
@@ -333,7 +333,7 @@ cd_builtin (WORD_LIST *list)
 #if 0
   else if (list->word->word[0] == '\0')
     {
-      builtin_error (_("null directory"));
+      builtin_error (_("null directory"));     /* POSIX cd implementation defined */
       return (EXECUTION_FAILURE);
     }
 #endif
@@ -347,19 +347,14 @@ cd_builtin (WORD_LIST *list)
          builtin_error (_("OLDPWD not set"));
          return (EXECUTION_FAILURE);
        }
-#if 0
-      lflag = interactive ? LCD_PRINTPATH : 0;
-#else
-      lflag = LCD_PRINTPATH;           /* According to SUSv3 */
-#endif
+      lflag = LCD_PRINTPATH;           /* POSIX cd `-' operand */
     }
-  else if (absolute_pathname (list->word->word))
+  else
     dirname = list->word->word;
-  else if (privileged_mode == 0 && (cdpath = get_string_value ("CDPATH")))
-    {
-      dirname = list->word->word;
 
-      /* Find directory in $CDPATH. */
+  if (privileged_mode == 0 && absolute_pathname (dirname) == 0 && (cdpath = get_string_value ("CDPATH")))
+    {
+      /* Find directory in $CDPATH, POSIX cd step 5. */
       path_index = 0;
       while (path = extract_colon_unit (cdpath, &path_index))
        {
@@ -390,8 +385,6 @@ cd_builtin (WORD_LIST *list)
            free (temp);
        }
     }
-  else
-    dirname = list->word->word;
 
   /* When we get here, DIRNAME is the directory to change to.  If we
      chdir successfully, just return. */
index b48e02a84943c93c6f89bf44057f84eb9e534208..a26bcd9b1c6a3322faa688993c3e82a866030040 100644 (file)
@@ -2720,8 +2720,10 @@ C\bCO\bON\bND\bDI\bIT\bTI\bIO\bON\bNA\bAL\bL E\bEX\bXP\bPR\bRE\bES\bSS\bSI\bIO\bON\bNS\bS
        bolic links and operate on the target of the link, rather than the link
        itself.
 
-       When used with [\b[[\b[, the <\b< and >\b> operators sort  lexicographically  using
-       the current locale.  The t\bte\bes\bst\bt command sorts using ASCII ordering.
+       When used with [\b[[\b[, or when the shell is in _\bp_\bo_\bs_\bi_\bx _\bm_\bo_\bd_\be, the <\b< and >\b>  op-
+       erators  sort  lexicographically  using  the  current locale.  When the
+       shell is not in _\bp_\bo_\bs_\bi_\bx _\bm_\bo_\bd_\be, the t\bte\bes\bst\bt command sorts using  ASCII  order-
+       ing.
 
        -\b-a\ba _\bf_\bi_\bl_\be
               True if _\bf_\bi_\bl_\be exists.
@@ -6317,8 +6319,10 @@ S\bSH\bHE\bEL\bLL\bL B\bBU\bUI\bIL\bLT\bTI\bIN\bN C\bCO\bOM\bMM\bMA\bAN\bND\bDS\bS
                      The  expression  is  parsed  and  evaluated  according to
                      precedence using the rules listed above.
 
-              When used with t\bte\bes\bst\bt or [\b[, the <\b< and  >\b>  operators  sort  lexico-
-              graphically using ASCII ordering.
+              If the shell is not in _\bp_\bo_\bs_\bi_\bx _\bm_\bo_\bd_\be, when used with t\bte\bes\bst\bt or [\b[, the
+              <\b<  and  >\b> operators sort lexicographically using ASCII ordering.
+              When the shell is in _\bp_\bo_\bs_\bi_\bx _\bm_\bo_\bd_\be, these operators sort using  the
+              current locale.
 
        t\bti\bim\bme\bes\bs  Print  the  accumulated  user and system times for the shell and
               for processes run from the shell.  The return status is 0.
@@ -6800,4 +6804,4 @@ B\bBU\bUG\bGS\bS
 
 
 
-GNU Bash 5.3                     2023 June 28                          BASH(1)
+GNU Bash 5.3                      2023 July 7                          BASH(1)
index dcbf2b69830b629698fb4c5241bc546339c98820..09e25ecfb1ec42d0a0fa6d7ca658a0cc20ead136 100644 (file)
@@ -5,12 +5,12 @@
 .\"    Case Western Reserve University
 .\"    chet.ramey@case.edu
 .\"
-.\"    Last Change: Wed Jun 28 14:06:27 EDT 2023
+.\"    Last Change: Fri Jul  7 15:07:53 EDT 2023
 .\"
 .\" bash_builtins, strip all but Built-Ins section
 .if \n(zZ=1 .ig zZ
 .if \n(zY=1 .ig zY
-.TH BASH 1 "2023 June 28" "GNU Bash 5.3"
+.TH BASH 1 "2023 July 7" "GNU Bash 5.3"
 .\"
 .\" There's some problem with having a `@'
 .\" in a tagged paragraph with the BSD man macros.
@@ -4874,9 +4874,12 @@ Unless otherwise specified, primaries that operate on files follow symbolic
 links and operate on the target of the link, rather than the link itself.
 .if t .sp 0.5
 .if n .sp 1
-When used with \fB[[\fP, the \fB<\fP and \fB>\fP operators sort
+When used with \fB[[\fP,
+or when the shell is in \fIposix mode\fP,
+the \fB<\fP and \fB>\fP operators sort
 lexicographically using the current locale.
-The \fBtest\fP command sorts using ASCII ordering.
+When the shell is not in \fIposix mode\fP,
+the \fBtest\fP command sorts using ASCII ordering.
 .sp 1
 .PD 0
 .TP
@@ -11028,8 +11031,11 @@ using the rules listed above.
 .if t .sp 0.5
 .if n .sp 1
 .LP
-When used with \fBtest\fP or \fB[\fP, the \fB<\fP and \fB>\fP operators
+If the shell is not in \fIposix mode\fP, 
+when used with \fBtest\fP or \fB[\fP, the \fB<\fP and \fB>\fP operators
 sort lexicographically using ASCII ordering.
+When the shell is in \fIposix mode\fP, these operators sort using the
+current locale.
 .RE
 .PD
 .TP
index 53234d3fa3cd8d068c91202935693bf864262d7b..228e08161ae11efa5007520793c1caed0d22c631 100644 (file)
@@ -3,7 +3,7 @@
 </HEAD>
 <BODY><TABLE WIDTH=100%>
 <TR>
-<TH ALIGN=LEFT width=33%>BASH(1)<TH ALIGN=CENTER width=33%>2023 June 28<TH ALIGN=RIGHT width=33%>BASH(1)
+<TH ALIGN=LEFT width=33%>BASH(1)<TH ALIGN=CENTER width=33%>2023 July 7<TH ALIGN=RIGHT width=33%>BASH(1)
 </TR>
 </TABLE>
 <BR><A HREF="#index">Index</A>
@@ -6160,9 +6160,12 @@ links and operate on the target of the link, rather than the link itself.
 <P>
 
 
-When used with <B>[[</B>, the <B>&lt;</B> and <B>&gt;</B> operators sort
+When used with <B>[[</B>,
+or when the shell is in <I>posix mode</I>,
+the <B>&lt;</B> and <B>&gt;</B> operators sort
 lexicographically using the current locale.
-The <B>test</B> command sorts using ASCII ordering.
+When the shell is not in <I>posix mode</I>,
+the <B>test</B> command sorts using ASCII ordering.
 <P>
 
 <DL COMPACT>
@@ -13849,8 +13852,11 @@ using the rules listed above.
 </DL>
 <P>
 
-When used with <B>test</B> or <B>[</B>, the <B>&lt;</B> and <B>&gt;</B> operators
+If the shell is not in <I>posix mode</I>, 
+when used with <B>test</B> or <B>[</B>, the <B>&lt;</B> and <B>&gt;</B> operators
 sort lexicographically using ASCII ordering.
+When the shell is in <I>posix mode</I>, these operators sort using the
+current locale.
 </DL>
 
 
@@ -15051,7 +15057,7 @@ There may be only one active coprocess at a time.
 <HR>
 <TABLE WIDTH=100%>
 <TR>
-<TH ALIGN=LEFT width=33%>GNU Bash 5.3<TH ALIGN=CENTER width=33%>2023 June 28<TH ALIGN=RIGHT width=33%>BASH(1)
+<TH ALIGN=LEFT width=33%>GNU Bash 5.3<TH ALIGN=CENTER width=33%>2023 July 7<TH ALIGN=RIGHT width=33%>BASH(1)
 </TR>
 </TABLE>
 <HR>
@@ -15157,7 +15163,7 @@ There may be only one active coprocess at a time.
 <DT><A HREF="#lbDI">BUGS</A><DD>
 </DL>
 <HR>
-This document was created by man2html from /usr/local/src/bash/bash-20230703/doc/bash.1.<BR>
-Time: 05 July 2023 11:27:18 EDT
+This document was created by man2html from /usr/local/src/bash/bash-20230705/doc/bash.1.<BR>
+Time: 07 July 2023 16:22:29 EDT
 </BODY>
 </HTML>
index 6f311af5876a7bea08ec8aca2d5538741a682933..ce81547371f5f80b1b64ff2d77b908d788749df6 100644 (file)
@@ -1,9 +1,9 @@
 This is bash.info, produced by makeinfo version 6.8 from bashref.texi.
 
 This text is a brief description of the features that are present in the
-Bash shell (version 5.3, 29 June 2023).
+Bash shell (version 5.3, 7 July 2023).
 
-   This is Edition 5.3, last updated 29 June 2023, of 'The GNU Bash
+   This is Edition 5.3, last updated 7 July 2023, of 'The GNU Bash
 Reference Manual', for 'Bash', Version 5.3.
 
    Copyright (C) 1988-2023 Free Software Foundation, Inc.
@@ -26,10 +26,10 @@ Bash Features
 *************
 
 This text is a brief description of the features that are present in the
-Bash shell (version 5.3, 29 June 2023).  The Bash home page is
+Bash shell (version 5.3, 7 July 2023).  The Bash home page is
 <http://www.gnu.org/software/bash/>.
 
-   This is Edition 5.3, last updated 29 June 2023, of 'The GNU Bash
+   This is Edition 5.3, last updated 7 July 2023, of 'The GNU Bash
 Reference Manual', for 'Bash', Version 5.3.
 
    Bash contains features that appear in other popular shells, and some
@@ -3613,8 +3613,25 @@ standard.
           The expression is parsed and evaluated according to precedence
           using the rules listed above.
 
-     When used with 'test' or '[', the '<' and '>' operators sort
-     lexicographically using ASCII ordering.
+     If the shell is not in POSIX mode, when used with 'test' or '[',
+     the '<' and '>' operators sort lexicographically using ASCII
+     ordering.  If the shell is in POSIX mode, these operators use the
+     current locale.
+
+     The historical operator-precedence parsing with 4 or more arguments
+     can lead to ambiguities when it encounters strings that look like
+     primaries.  The POSIX standard has deprecated the '-a' and '-o'
+     primaries and enclosing expressions within parentheses.  Scripts
+     should no longer use them.  It's much more reliable to restrict
+     test invocations to a single primary, and to replace uses of '-a'
+     and '-o' with the shell's '&&' and '||' list operators.  For
+     example, use
+
+          test -n string1 && test -n string2
+
+     instead of
+
+          test -n string1 -a -n string2
 
 'times'
           times
@@ -7493,7 +7510,12 @@ startup files.
   66. The 'test' builtin compares strings using the current locale when
      processing the '<' and '>' binary operators.
 
-  67. Command substitutions don't set the '?' special parameter.  The
+  67. The 'test' builtin's '-t' unary primary requires an argument.
+     Historical versions of 'test' made the argument optional in certain
+     cases, and bash attempts to accommodate those for backwards
+     compatibility.
+
+  68. Command substitutions don't set the '?' special parameter.  The
      exit status of a simple command without a command word is still the
      exit status of the last command substitution that occurred while
      evaluating the variable assignments and redirections in that
@@ -12107,19 +12129,19 @@ D.1 Index of Shell Builtin Commands
 * test:                                  Bourne Shell Builtins.
                                                               (line 281)
 * times:                                 Bourne Shell Builtins.
-                                                              (line 366)
+                                                              (line 383)
 * trap:                                  Bourne Shell Builtins.
-                                                              (line 372)
+                                                              (line 389)
 * true:                                  Bourne Shell Builtins.
-                                                              (line 434)
+                                                              (line 451)
 * type:                                  Bash Builtins.       (line 615)
 * typeset:                               Bash Builtins.       (line 653)
 * ulimit:                                Bash Builtins.       (line 659)
 * umask:                                 Bourne Shell Builtins.
-                                                              (line 439)
+                                                              (line 456)
 * unalias:                               Bash Builtins.       (line 765)
 * unset:                                 Bourne Shell Builtins.
-                                                              (line 457)
+                                                              (line 474)
 * wait:                                  Job Control Builtins.
                                                               (line  76)
 
@@ -12794,138 +12816,138 @@ D.5 Concept Index
 
 \1f
 Tag Table:
-Node: Top\7f886
-Node: Introduction\7f2795
-Node: What is Bash?\7f3008
-Node: What is a shell?\7f4119
-Node: Definitions\7f6654
-Node: Basic Shell Features\7f9602
-Node: Shell Syntax\7f10818
-Node: Shell Operation\7f11841
-Node: Quoting\7f13131
-Node: Escape Character\7f14432
-Node: Single Quotes\7f14914
-Node: Double Quotes\7f15259
-Node: ANSI-C Quoting\7f16534
-Node: Locale Translation\7f17843
-Node: Creating Internationalized Scripts\7f19151
-Node: Comments\7f23265
-Node: Shell Commands\7f23880
-Node: Reserved Words\7f24815
-Node: Simple Commands\7f25568
-Node: Pipelines\7f26219
-Node: Lists\7f29202
-Node: Compound Commands\7f30994
-Node: Looping Constructs\7f32003
-Node: Conditional Constructs\7f34495
-Node: Command Grouping\7f48980
-Node: Coprocesses\7f50455
-Node: GNU Parallel\7f53115
-Node: Shell Functions\7f54029
-Node: Shell Parameters\7f61911
-Node: Positional Parameters\7f66296
-Node: Special Parameters\7f67195
-Node: Shell Expansions\7f70406
-Node: Brace Expansion\7f72491
-Node: Tilde Expansion\7f75222
-Node: Shell Parameter Expansion\7f77840
-Node: Command Substitution\7f96239
-Node: Arithmetic Expansion\7f99700
-Node: Process Substitution\7f100665
-Node: Word Splitting\7f101782
-Node: Filename Expansion\7f103827
-Node: Pattern Matching\7f106757
-Node: Quote Removal\7f111756
-Node: Redirections\7f112048
-Node: Executing Commands\7f121738
-Node: Simple Command Expansion\7f122405
-Node: Command Search and Execution\7f124512
-Node: Command Execution Environment\7f126896
-Node: Environment\7f129928
-Node: Exit Status\7f131588
-Node: Signals\7f133369
-Node: Shell Scripts\7f136815
-Node: Shell Builtin Commands\7f139839
-Node: Bourne Shell Builtins\7f141874
-Node: Bash Builtins\7f164278
-Node: Modifying Shell Behavior\7f196274
-Node: The Set Builtin\7f196616
-Node: The Shopt Builtin\7f207211
-Node: Special Builtins\7f223215
-Node: Shell Variables\7f224191
-Node: Bourne Shell Variables\7f224625
-Node: Bash Variables\7f226726
-Node: Bash Features\7f261680
-Node: Invoking Bash\7f262690
-Node: Bash Startup Files\7f268700
-Node: Interactive Shells\7f273828
-Node: What is an Interactive Shell?\7f274236
-Node: Is this Shell Interactive?\7f274882
-Node: Interactive Shell Behavior\7f275694
-Node: Bash Conditional Expressions\7f279320
-Node: Shell Arithmetic\7f283959
-Node: Aliases\7f286917
-Node: Arrays\7f289808
-Node: The Directory Stack\7f296368
-Node: Directory Stack Builtins\7f297149
-Node: Controlling the Prompt\7f301406
-Node: The Restricted Shell\7f304368
-Node: Bash POSIX Mode\7f306975
-Node: Shell Compatibility Mode\7f322888
-Node: Job Control\7f331129
-Node: Job Control Basics\7f331586
-Node: Job Control Builtins\7f336585
-Node: Job Control Variables\7f342377
-Node: Command Line Editing\7f343530
-Node: Introduction and Notation\7f345198
-Node: Readline Interaction\7f346818
-Node: Readline Bare Essentials\7f348006
-Node: Readline Movement Commands\7f349792
-Node: Readline Killing Commands\7f350749
-Node: Readline Arguments\7f352667
-Node: Searching\7f353708
-Node: Readline Init File\7f355891
-Node: Readline Init File Syntax\7f357149
-Node: Conditional Init Constructs\7f380937
-Node: Sample Init File\7f385130
-Node: Bindable Readline Commands\7f388251
-Node: Commands For Moving\7f389452
-Node: Commands For History\7f391500
-Node: Commands For Text\7f396491
-Node: Commands For Killing\7f400137
-Node: Numeric Arguments\7f403167
-Node: Commands For Completion\7f404303
-Node: Keyboard Macros\7f408491
-Node: Miscellaneous Commands\7f409176
-Node: Readline vi Mode\7f415211
-Node: Programmable Completion\7f416115
-Node: Programmable Completion Builtins\7f423892
-Node: A Programmable Completion Example\7f435009
-Node: Using History Interactively\7f440254
-Node: Bash History Facilities\7f440935
-Node: Bash History Builtins\7f443937
-Node: History Interaction\7f448958
-Node: Event Designators\7f452575
-Node: Word Designators\7f453926
-Node: Modifiers\7f455683
-Node: Installing Bash\7f457488
-Node: Basic Installation\7f458622
-Node: Compilers and Options\7f462341
-Node: Compiling For Multiple Architectures\7f463079
-Node: Installation Names\7f464768
-Node: Specifying the System Type\7f466874
-Node: Sharing Defaults\7f467588
-Node: Operation Controls\7f468258
-Node: Optional Features\7f469213
-Node: Reporting Bugs\7f480429
-Node: Major Differences From The Bourne Shell\7f481760
-Node: GNU Free Documentation License\7f498606
-Node: Indexes\7f523780
-Node: Builtin Index\7f524231
-Node: Reserved Word Index\7f531329
-Node: Variable Index\7f533774
-Node: Function Index\7f550905
-Node: Concept Index\7f564686
+Node: Top\7f884
+Node: Introduction\7f2791
+Node: What is Bash?\7f3004
+Node: What is a shell?\7f4115
+Node: Definitions\7f6650
+Node: Basic Shell Features\7f9598
+Node: Shell Syntax\7f10814
+Node: Shell Operation\7f11837
+Node: Quoting\7f13127
+Node: Escape Character\7f14428
+Node: Single Quotes\7f14910
+Node: Double Quotes\7f15255
+Node: ANSI-C Quoting\7f16530
+Node: Locale Translation\7f17839
+Node: Creating Internationalized Scripts\7f19147
+Node: Comments\7f23261
+Node: Shell Commands\7f23876
+Node: Reserved Words\7f24811
+Node: Simple Commands\7f25564
+Node: Pipelines\7f26215
+Node: Lists\7f29198
+Node: Compound Commands\7f30990
+Node: Looping Constructs\7f31999
+Node: Conditional Constructs\7f34491
+Node: Command Grouping\7f48976
+Node: Coprocesses\7f50451
+Node: GNU Parallel\7f53111
+Node: Shell Functions\7f54025
+Node: Shell Parameters\7f61907
+Node: Positional Parameters\7f66292
+Node: Special Parameters\7f67191
+Node: Shell Expansions\7f70402
+Node: Brace Expansion\7f72487
+Node: Tilde Expansion\7f75218
+Node: Shell Parameter Expansion\7f77836
+Node: Command Substitution\7f96235
+Node: Arithmetic Expansion\7f99696
+Node: Process Substitution\7f100661
+Node: Word Splitting\7f101778
+Node: Filename Expansion\7f103823
+Node: Pattern Matching\7f106753
+Node: Quote Removal\7f111752
+Node: Redirections\7f112044
+Node: Executing Commands\7f121734
+Node: Simple Command Expansion\7f122401
+Node: Command Search and Execution\7f124508
+Node: Command Execution Environment\7f126892
+Node: Environment\7f129924
+Node: Exit Status\7f131584
+Node: Signals\7f133365
+Node: Shell Scripts\7f136811
+Node: Shell Builtin Commands\7f139835
+Node: Bourne Shell Builtins\7f141870
+Node: Bash Builtins\7f165003
+Node: Modifying Shell Behavior\7f196999
+Node: The Set Builtin\7f197341
+Node: The Shopt Builtin\7f207936
+Node: Special Builtins\7f223940
+Node: Shell Variables\7f224916
+Node: Bourne Shell Variables\7f225350
+Node: Bash Variables\7f227451
+Node: Bash Features\7f262405
+Node: Invoking Bash\7f263415
+Node: Bash Startup Files\7f269425
+Node: Interactive Shells\7f274553
+Node: What is an Interactive Shell?\7f274961
+Node: Is this Shell Interactive?\7f275607
+Node: Interactive Shell Behavior\7f276419
+Node: Bash Conditional Expressions\7f280045
+Node: Shell Arithmetic\7f284684
+Node: Aliases\7f287642
+Node: Arrays\7f290533
+Node: The Directory Stack\7f297093
+Node: Directory Stack Builtins\7f297874
+Node: Controlling the Prompt\7f302131
+Node: The Restricted Shell\7f305093
+Node: Bash POSIX Mode\7f307700
+Node: Shell Compatibility Mode\7f323840
+Node: Job Control\7f332081
+Node: Job Control Basics\7f332538
+Node: Job Control Builtins\7f337537
+Node: Job Control Variables\7f343329
+Node: Command Line Editing\7f344482
+Node: Introduction and Notation\7f346150
+Node: Readline Interaction\7f347770
+Node: Readline Bare Essentials\7f348958
+Node: Readline Movement Commands\7f350744
+Node: Readline Killing Commands\7f351701
+Node: Readline Arguments\7f353619
+Node: Searching\7f354660
+Node: Readline Init File\7f356843
+Node: Readline Init File Syntax\7f358101
+Node: Conditional Init Constructs\7f381889
+Node: Sample Init File\7f386082
+Node: Bindable Readline Commands\7f389203
+Node: Commands For Moving\7f390404
+Node: Commands For History\7f392452
+Node: Commands For Text\7f397443
+Node: Commands For Killing\7f401089
+Node: Numeric Arguments\7f404119
+Node: Commands For Completion\7f405255
+Node: Keyboard Macros\7f409443
+Node: Miscellaneous Commands\7f410128
+Node: Readline vi Mode\7f416163
+Node: Programmable Completion\7f417067
+Node: Programmable Completion Builtins\7f424844
+Node: A Programmable Completion Example\7f435961
+Node: Using History Interactively\7f441206
+Node: Bash History Facilities\7f441887
+Node: Bash History Builtins\7f444889
+Node: History Interaction\7f449910
+Node: Event Designators\7f453527
+Node: Word Designators\7f454878
+Node: Modifiers\7f456635
+Node: Installing Bash\7f458440
+Node: Basic Installation\7f459574
+Node: Compilers and Options\7f463293
+Node: Compiling For Multiple Architectures\7f464031
+Node: Installation Names\7f465720
+Node: Specifying the System Type\7f467826
+Node: Sharing Defaults\7f468540
+Node: Operation Controls\7f469210
+Node: Optional Features\7f470165
+Node: Reporting Bugs\7f481381
+Node: Major Differences From The Bourne Shell\7f482712
+Node: GNU Free Documentation License\7f499558
+Node: Indexes\7f524732
+Node: Builtin Index\7f525183
+Node: Reserved Word Index\7f532281
+Node: Variable Index\7f534726
+Node: Function Index\7f551857
+Node: Concept Index\7f565638
 \1f
 End Tag Table
 
index 9a8c87efc2ccffa0cb16b460e4df78c7ee782c7d..285e5e3864abdb63400d7aa8ac1a433edf616208 100644 (file)
@@ -2,9 +2,9 @@ This is bashref.info, produced by makeinfo version 6.8 from
 bashref.texi.
 
 This text is a brief description of the features that are present in the
-Bash shell (version 5.3, 29 June 2023).
+Bash shell (version 5.3, 7 July 2023).
 
-   This is Edition 5.3, last updated 29 June 2023, of 'The GNU Bash
+   This is Edition 5.3, last updated 7 July 2023, of 'The GNU Bash
 Reference Manual', for 'Bash', Version 5.3.
 
    Copyright (C) 1988-2023 Free Software Foundation, Inc.
@@ -27,10 +27,10 @@ Bash Features
 *************
 
 This text is a brief description of the features that are present in the
-Bash shell (version 5.3, 29 June 2023).  The Bash home page is
+Bash shell (version 5.3, 7 July 2023).  The Bash home page is
 <http://www.gnu.org/software/bash/>.
 
-   This is Edition 5.3, last updated 29 June 2023, of 'The GNU Bash
+   This is Edition 5.3, last updated 7 July 2023, of 'The GNU Bash
 Reference Manual', for 'Bash', Version 5.3.
 
    Bash contains features that appear in other popular shells, and some
@@ -3614,8 +3614,25 @@ standard.
           The expression is parsed and evaluated according to precedence
           using the rules listed above.
 
-     When used with 'test' or '[', the '<' and '>' operators sort
-     lexicographically using ASCII ordering.
+     If the shell is not in POSIX mode, when used with 'test' or '[',
+     the '<' and '>' operators sort lexicographically using ASCII
+     ordering.  If the shell is in POSIX mode, these operators use the
+     current locale.
+
+     The historical operator-precedence parsing with 4 or more arguments
+     can lead to ambiguities when it encounters strings that look like
+     primaries.  The POSIX standard has deprecated the '-a' and '-o'
+     primaries and enclosing expressions within parentheses.  Scripts
+     should no longer use them.  It's much more reliable to restrict
+     test invocations to a single primary, and to replace uses of '-a'
+     and '-o' with the shell's '&&' and '||' list operators.  For
+     example, use
+
+          test -n string1 && test -n string2
+
+     instead of
+
+          test -n string1 -a -n string2
 
 'times'
           times
@@ -7494,7 +7511,12 @@ startup files.
   66. The 'test' builtin compares strings using the current locale when
      processing the '<' and '>' binary operators.
 
-  67. Command substitutions don't set the '?' special parameter.  The
+  67. The 'test' builtin's '-t' unary primary requires an argument.
+     Historical versions of 'test' made the argument optional in certain
+     cases, and bash attempts to accommodate those for backwards
+     compatibility.
+
+  68. Command substitutions don't set the '?' special parameter.  The
      exit status of a simple command without a command word is still the
      exit status of the last command substitution that occurred while
      evaluating the variable assignments and redirections in that
@@ -12108,19 +12130,19 @@ D.1 Index of Shell Builtin Commands
 * test:                                  Bourne Shell Builtins.
                                                               (line 281)
 * times:                                 Bourne Shell Builtins.
-                                                              (line 366)
+                                                              (line 383)
 * trap:                                  Bourne Shell Builtins.
-                                                              (line 372)
+                                                              (line 389)
 * true:                                  Bourne Shell Builtins.
-                                                              (line 434)
+                                                              (line 451)
 * type:                                  Bash Builtins.       (line 615)
 * typeset:                               Bash Builtins.       (line 653)
 * ulimit:                                Bash Builtins.       (line 659)
 * umask:                                 Bourne Shell Builtins.
-                                                              (line 439)
+                                                              (line 456)
 * unalias:                               Bash Builtins.       (line 765)
 * unset:                                 Bourne Shell Builtins.
-                                                              (line 457)
+                                                              (line 474)
 * wait:                                  Job Control Builtins.
                                                               (line  76)
 
@@ -12795,138 +12817,138 @@ D.5 Concept Index
 
 \1f
 Tag Table:
-Node: Top\7f889
-Node: Introduction\7f2801
-Node: What is Bash?\7f3017
-Node: What is a shell?\7f4131
-Node: Definitions\7f6669
-Node: Basic Shell Features\7f9620
-Node: Shell Syntax\7f10839
-Node: Shell Operation\7f11865
-Node: Quoting\7f13158
-Node: Escape Character\7f14462
-Node: Single Quotes\7f14947
-Node: Double Quotes\7f15295
-Node: ANSI-C Quoting\7f16573
-Node: Locale Translation\7f17885
-Node: Creating Internationalized Scripts\7f19196
-Node: Comments\7f23313
-Node: Shell Commands\7f23931
-Node: Reserved Words\7f24869
-Node: Simple Commands\7f25625
-Node: Pipelines\7f26279
-Node: Lists\7f29265
-Node: Compound Commands\7f31060
-Node: Looping Constructs\7f32072
-Node: Conditional Constructs\7f34567
-Node: Command Grouping\7f49055
-Node: Coprocesses\7f50533
-Node: GNU Parallel\7f53196
-Node: Shell Functions\7f54113
-Node: Shell Parameters\7f61998
-Node: Positional Parameters\7f66386
-Node: Special Parameters\7f67288
-Node: Shell Expansions\7f70502
-Node: Brace Expansion\7f72590
-Node: Tilde Expansion\7f75324
-Node: Shell Parameter Expansion\7f77945
-Node: Command Substitution\7f96347
-Node: Arithmetic Expansion\7f99811
-Node: Process Substitution\7f100779
-Node: Word Splitting\7f101899
-Node: Filename Expansion\7f103947
-Node: Pattern Matching\7f106880
-Node: Quote Removal\7f111882
-Node: Redirections\7f112177
-Node: Executing Commands\7f121870
-Node: Simple Command Expansion\7f122540
-Node: Command Search and Execution\7f124650
-Node: Command Execution Environment\7f127037
-Node: Environment\7f130072
-Node: Exit Status\7f131735
-Node: Signals\7f133519
-Node: Shell Scripts\7f136968
-Node: Shell Builtin Commands\7f139995
-Node: Bourne Shell Builtins\7f142033
-Node: Bash Builtins\7f164440
-Node: Modifying Shell Behavior\7f196439
-Node: The Set Builtin\7f196784
-Node: The Shopt Builtin\7f207382
-Node: Special Builtins\7f223389
-Node: Shell Variables\7f224368
-Node: Bourne Shell Variables\7f224805
-Node: Bash Variables\7f226909
-Node: Bash Features\7f261866
-Node: Invoking Bash\7f262879
-Node: Bash Startup Files\7f268892
-Node: Interactive Shells\7f274023
-Node: What is an Interactive Shell?\7f274434
-Node: Is this Shell Interactive?\7f275083
-Node: Interactive Shell Behavior\7f275898
-Node: Bash Conditional Expressions\7f279527
-Node: Shell Arithmetic\7f284169
-Node: Aliases\7f287130
-Node: Arrays\7f290024
-Node: The Directory Stack\7f296587
-Node: Directory Stack Builtins\7f297371
-Node: Controlling the Prompt\7f301631
-Node: The Restricted Shell\7f304596
-Node: Bash POSIX Mode\7f307206
-Node: Shell Compatibility Mode\7f323122
-Node: Job Control\7f331366
-Node: Job Control Basics\7f331826
-Node: Job Control Builtins\7f336828
-Node: Job Control Variables\7f342623
-Node: Command Line Editing\7f343779
-Node: Introduction and Notation\7f345450
-Node: Readline Interaction\7f347073
-Node: Readline Bare Essentials\7f348264
-Node: Readline Movement Commands\7f350053
-Node: Readline Killing Commands\7f351013
-Node: Readline Arguments\7f352934
-Node: Searching\7f353978
-Node: Readline Init File\7f356164
-Node: Readline Init File Syntax\7f357425
-Node: Conditional Init Constructs\7f381216
-Node: Sample Init File\7f385412
-Node: Bindable Readline Commands\7f388536
-Node: Commands For Moving\7f389740
-Node: Commands For History\7f391791
-Node: Commands For Text\7f396785
-Node: Commands For Killing\7f400434
-Node: Numeric Arguments\7f403467
-Node: Commands For Completion\7f404606
-Node: Keyboard Macros\7f408797
-Node: Miscellaneous Commands\7f409485
-Node: Readline vi Mode\7f415523
-Node: Programmable Completion\7f416430
-Node: Programmable Completion Builtins\7f424210
-Node: A Programmable Completion Example\7f435330
-Node: Using History Interactively\7f440578
-Node: Bash History Facilities\7f441262
-Node: Bash History Builtins\7f444267
-Node: History Interaction\7f449291
-Node: Event Designators\7f452911
-Node: Word Designators\7f454265
-Node: Modifiers\7f456025
-Node: Installing Bash\7f457833
-Node: Basic Installation\7f458970
-Node: Compilers and Options\7f462692
-Node: Compiling For Multiple Architectures\7f463433
-Node: Installation Names\7f465125
-Node: Specifying the System Type\7f467234
-Node: Sharing Defaults\7f467951
-Node: Operation Controls\7f468624
-Node: Optional Features\7f469582
-Node: Reporting Bugs\7f480801
-Node: Major Differences From The Bourne Shell\7f482135
-Node: GNU Free Documentation License\7f498984
-Node: Indexes\7f524161
-Node: Builtin Index\7f524615
-Node: Reserved Word Index\7f531716
-Node: Variable Index\7f534164
-Node: Function Index\7f551298
-Node: Concept Index\7f565082
+Node: Top\7f887
+Node: Introduction\7f2797
+Node: What is Bash?\7f3013
+Node: What is a shell?\7f4127
+Node: Definitions\7f6665
+Node: Basic Shell Features\7f9616
+Node: Shell Syntax\7f10835
+Node: Shell Operation\7f11861
+Node: Quoting\7f13154
+Node: Escape Character\7f14458
+Node: Single Quotes\7f14943
+Node: Double Quotes\7f15291
+Node: ANSI-C Quoting\7f16569
+Node: Locale Translation\7f17881
+Node: Creating Internationalized Scripts\7f19192
+Node: Comments\7f23309
+Node: Shell Commands\7f23927
+Node: Reserved Words\7f24865
+Node: Simple Commands\7f25621
+Node: Pipelines\7f26275
+Node: Lists\7f29261
+Node: Compound Commands\7f31056
+Node: Looping Constructs\7f32068
+Node: Conditional Constructs\7f34563
+Node: Command Grouping\7f49051
+Node: Coprocesses\7f50529
+Node: GNU Parallel\7f53192
+Node: Shell Functions\7f54109
+Node: Shell Parameters\7f61994
+Node: Positional Parameters\7f66382
+Node: Special Parameters\7f67284
+Node: Shell Expansions\7f70498
+Node: Brace Expansion\7f72586
+Node: Tilde Expansion\7f75320
+Node: Shell Parameter Expansion\7f77941
+Node: Command Substitution\7f96343
+Node: Arithmetic Expansion\7f99807
+Node: Process Substitution\7f100775
+Node: Word Splitting\7f101895
+Node: Filename Expansion\7f103943
+Node: Pattern Matching\7f106876
+Node: Quote Removal\7f111878
+Node: Redirections\7f112173
+Node: Executing Commands\7f121866
+Node: Simple Command Expansion\7f122536
+Node: Command Search and Execution\7f124646
+Node: Command Execution Environment\7f127033
+Node: Environment\7f130068
+Node: Exit Status\7f131731
+Node: Signals\7f133515
+Node: Shell Scripts\7f136964
+Node: Shell Builtin Commands\7f139991
+Node: Bourne Shell Builtins\7f142029
+Node: Bash Builtins\7f165165
+Node: Modifying Shell Behavior\7f197164
+Node: The Set Builtin\7f197509
+Node: The Shopt Builtin\7f208107
+Node: Special Builtins\7f224114
+Node: Shell Variables\7f225093
+Node: Bourne Shell Variables\7f225530
+Node: Bash Variables\7f227634
+Node: Bash Features\7f262591
+Node: Invoking Bash\7f263604
+Node: Bash Startup Files\7f269617
+Node: Interactive Shells\7f274748
+Node: What is an Interactive Shell?\7f275159
+Node: Is this Shell Interactive?\7f275808
+Node: Interactive Shell Behavior\7f276623
+Node: Bash Conditional Expressions\7f280252
+Node: Shell Arithmetic\7f284894
+Node: Aliases\7f287855
+Node: Arrays\7f290749
+Node: The Directory Stack\7f297312
+Node: Directory Stack Builtins\7f298096
+Node: Controlling the Prompt\7f302356
+Node: The Restricted Shell\7f305321
+Node: Bash POSIX Mode\7f307931
+Node: Shell Compatibility Mode\7f324074
+Node: Job Control\7f332318
+Node: Job Control Basics\7f332778
+Node: Job Control Builtins\7f337780
+Node: Job Control Variables\7f343575
+Node: Command Line Editing\7f344731
+Node: Introduction and Notation\7f346402
+Node: Readline Interaction\7f348025
+Node: Readline Bare Essentials\7f349216
+Node: Readline Movement Commands\7f351005
+Node: Readline Killing Commands\7f351965
+Node: Readline Arguments\7f353886
+Node: Searching\7f354930
+Node: Readline Init File\7f357116
+Node: Readline Init File Syntax\7f358377
+Node: Conditional Init Constructs\7f382168
+Node: Sample Init File\7f386364
+Node: Bindable Readline Commands\7f389488
+Node: Commands For Moving\7f390692
+Node: Commands For History\7f392743
+Node: Commands For Text\7f397737
+Node: Commands For Killing\7f401386
+Node: Numeric Arguments\7f404419
+Node: Commands For Completion\7f405558
+Node: Keyboard Macros\7f409749
+Node: Miscellaneous Commands\7f410437
+Node: Readline vi Mode\7f416475
+Node: Programmable Completion\7f417382
+Node: Programmable Completion Builtins\7f425162
+Node: A Programmable Completion Example\7f436282
+Node: Using History Interactively\7f441530
+Node: Bash History Facilities\7f442214
+Node: Bash History Builtins\7f445219
+Node: History Interaction\7f450243
+Node: Event Designators\7f453863
+Node: Word Designators\7f455217
+Node: Modifiers\7f456977
+Node: Installing Bash\7f458785
+Node: Basic Installation\7f459922
+Node: Compilers and Options\7f463644
+Node: Compiling For Multiple Architectures\7f464385
+Node: Installation Names\7f466077
+Node: Specifying the System Type\7f468186
+Node: Sharing Defaults\7f468903
+Node: Operation Controls\7f469576
+Node: Optional Features\7f470534
+Node: Reporting Bugs\7f481753
+Node: Major Differences From The Bourne Shell\7f483087
+Node: GNU Free Documentation License\7f499936
+Node: Indexes\7f525113
+Node: Builtin Index\7f525567
+Node: Reserved Word Index\7f532668
+Node: Variable Index\7f535116
+Node: Function Index\7f552250
+Node: Concept Index\7f566034
 \1f
 End Tag Table
 
index 85e729d5e026dc7411791373f3058582ad0b4d3f..9f91dccb5bef9ddbb55aa084e784c342cffb7112 100644 (file)
@@ -4288,8 +4288,30 @@ The expression is parsed and evaluated according to precedence
 using the rules listed above.
 @end table
 
-When used with @code{test} or @samp{[}, the @samp{<} and @samp{>}
+If the shell is not in @sc{posix} mode,
+when used with @code{test} or @samp{[}, the @samp{<} and @samp{>}
 operators sort lexicographically using ASCII ordering.
+If the shell is in @sc{posix} mode, these operators use the current locale.
+
+The historical operator-precedence parsing with 4 or more arguments can
+lead to ambiguities when it encounters strings that look like primaries.
+The @sc{posix} standard has deprecated the @option{-a} and @option{-o}
+primaries and enclosing expressions within parentheses.
+Scripts should no longer use them.
+It's much more reliable to restrict test invocations to a single primary,
+and to replace uses of @option{-a} and @option{-o} with the shell's
+@code{&&} and @code{||} list operators. For example, use
+
+@example
+test -n string1 && test -n string2
+@end example
+
+@noindent
+instead of
+
+@example
+test -n string1 -a -n string2
+@end example
 
 @item times
 @btindex times
@@ -8700,6 +8722,11 @@ character will escape it and the backslash will be removed.
 The @code{test} builtin compares strings using the current locale when
 processing the @samp{<} and @samp{>} binary operators.
 
+@item
+The @code{test} builtin's @option{-t} unary primary requires an argument.
+Historical versions of @code{test} made the argument optional in certain
+cases, and bash attempts to accommodate those for backwards compatibility.
+
 @item
 Command substitutions don't set the @samp{?} special parameter. The exit
 status of a simple command without a command word is still the exit status
index 159f956fe3d94c331960c6f69870e8abe212209a..5e2d1710c7bb6460a07672b34e0f1d26a65f5946 100644 (file)
@@ -2,10 +2,10 @@
 Copyright (C) 1988-2023 Free Software Foundation, Inc.
 @end ignore
 
-@set LASTCHANGE Thu Jun 29 16:25:08 EDT 2023
+@set LASTCHANGE Fri Jul  7 15:07:53 EDT 2023
 
 @set EDITION 5.3
 @set VERSION 5.3
 
-@set UPDATED 29 June 2023
-@set UPDATED-MONTH June 2023
+@set UPDATED 7 July 2023
+@set UPDATED-MONTH July 2023
diff --git a/examples/scripts/secure-script b/examples/scripts/secure-script
new file mode 100644 (file)
index 0000000..e26802a
--- /dev/null
@@ -0,0 +1,31 @@
+# if we are worried somehow about inheriting a function for unset or exec,
+# set posix mode, then unset it later
+POSIXLY_CORRECT=1
+
+# make sure to run with bash -p to prevent inheriting functions. you can
+# do this (if the script does not need to run setuid) or use the
+# POSIXLY_CORRECT setting above (as long as you run set +o posix as done below)
+#case $SHELLOPTS in
+#*privileged*) ;;
+#*)    \exec /bin/bash -p $0 "$@" ;;
+#esac
+
+# unset is a special builtin and will be found before functions; quoting it
+# will prevent alias expansion
+# add any other shell builtins you're concerned about
+\unset -f command builtin unset shopt set unalias hash
+\unset -f read true exit echo printf
+
+# remove all aliases and disable alias expansion
+\unalias -a
+\shopt -u expand_aliases
+
+# and make sure we're no longer running in posix mode
+set +o posix
+
+# get rid of any hashed commands
+hash -r
+
+# if you're concerned about PATH spoofing, make sure to have a path that
+# will find the standard utilities
+#PATH=$(command getconf -p getconf PATH):$PATH
diff --git a/jobs.c b/jobs.c
index cda155cf808970fd6fa7f141fcd3147fb454029d..4b8f6efa3364b1d36125b59f5293c52a16156f29 100644 (file)
--- a/jobs.c
+++ b/jobs.c
@@ -3587,12 +3587,16 @@ start_job (int job, int foreground)
     {
       get_tty_state ();
       save_stty = shell_tty_info;
+      jobs[job]->flags &= ~J_ASYNC;    /* no longer async */
       /* Give the terminal to this job. */
       if (IS_JOBCONTROL (job))
        give_terminal_to (jobs[job]->pgrp, 0);
     }
   else
-    jobs[job]->flags &= ~J_FOREGROUND;
+    {
+      jobs[job]->flags &= ~J_FOREGROUND;
+      jobs[job]->flags |= J_ASYNC;     /* running in background now */
+    }
 
   /* If the job is already running, then don't bother jump-starting it. */
   if (already_running == 0)
diff --git a/shell.c b/shell.c
index 9f1934d23a89389bcc5f3885fdd026b03b99e22c..e74460532c9f15079eeccc1f9e80ed0db7b5e019 100644 (file)
--- a/shell.c
+++ b/shell.c
@@ -117,7 +117,8 @@ COMMAND *global_command = (COMMAND *)NULL;
 /* Information about the current user. */
 struct user_info current_user =
 {
-  (uid_t)-1, (uid_t)-1, (gid_t)-1, (gid_t)-1,
+  (uid_t)-1, (uid_t)-1, (uid_t)-1,
+  (gid_t)-1, (gid_t)-1, (gid_t)-1,
   (char *)NULL, (char *)NULL, (char *)NULL
 };
 
@@ -1298,7 +1299,22 @@ uidget (void)
 {
   uid_t u;
 
-  u = getuid ();
+  u = current_user.uid;
+
+#if HAVE_SETRESUID
+  (void) getresuid (&current_user.uid, &current_user.euid, &current_user.saveuid);
+#else
+  current_user.uid = getuid ();
+  current_user.euid = geteuid ();
+#endif
+
+#if HAVE_SETRESGID
+  (void) getresgid (&current_user.gid, &current_user.egid, &current_user.savegid);
+#else
+  current_user.gid = getgid ();
+  current_user.egid = getegid ();
+#endif
+
   if (current_user.uid != u)
     {
       FREE (current_user.user_name);
@@ -1306,10 +1322,6 @@ uidget (void)
       FREE (current_user.home_dir);
       current_user.user_name = current_user.shell = current_user.home_dir = NULL;
     }
-  current_user.uid = u;
-  current_user.gid = getgid ();
-  current_user.euid = geteuid ();
-  current_user.egid = getegid ();
 
   /* See whether or not we are running setuid or setgid. */
   return (current_user.uid != current_user.euid) ||
@@ -1319,13 +1331,17 @@ uidget (void)
 void
 disable_priv_mode (void)
 {
-  int e;
+  int e, r;
 
+  r = 0;
 #if HAVE_SETRESUID
-  if (setresuid (current_user.uid, current_user.uid, current_user.uid) < 0)
+  if (current_user.euid != current_user.uid || current_user.saveuid != current_user.uid)
+    r = setresuid (current_user.uid, current_user.uid, current_user.uid) ;
 #else
-  if (setuid (current_user.uid) < 0)
+  if (current_user.euid != current_user.uid)
+    r = setuid (current_user.uid);
 #endif
+  if (r < 0)
     {
       e = errno;
       sys_error (_("cannot set uid to %d: effective uid %d"), current_user.uid, current_user.euid);
@@ -1334,15 +1350,23 @@ disable_priv_mode (void)
        exit (e);
 #endif
     }
+
+  r = 0;
 #if HAVE_SETRESGID
-  if (setresgid (current_user.gid, current_user.gid, current_user.gid) < 0)
+  if (current_user.egid != current_user.gid || current_user.savegid != current_user.gid)
+    r = setresgid (current_user.gid, current_user.gid, current_user.gid);
 #else
-  if (setgid (current_user.gid) < 0)
+  if (current_user.egid != current_user.gid)
+    r = setgid (current_user.gid);
 #endif
+  if (r < 0)
     sys_error (_("cannot set gid to %d: effective gid %d"), current_user.gid, current_user.egid);
 
   current_user.euid = current_user.uid;
   current_user.egid = current_user.gid;
+
+  current_user.saveuid = current_user.uid;
+  current_user.savegid = current_user.gid;
 }
 
 #if defined (WORDEXP_OPTION)
diff --git a/shell.h b/shell.h
index 055ba9f50dd534b41f9d1cfc80ac9fb5e9ed3936..6167372695dc96ff30bf267cf0af8bd8515e620f 100644 (file)
--- a/shell.h
+++ b/shell.h
@@ -148,8 +148,8 @@ struct fd_bitmap {
 
 /* Information about the current user. */
 struct user_info {
-  uid_t uid, euid;
-  gid_t gid, egid;
+  uid_t uid, euid, saveuid;
+  gid_t gid, egid, savegid;
   char *user_name;
   char *shell;         /* shell from the password file */
   char *home_dir;
diff --git a/test.c b/test.c
index 2b12197a523035406f17fe135b0ed4c7a29c1ea5..aa01926c5b3cac191388782e03ce4e7f2cf64e89 100644 (file)
--- a/test.c
+++ b/test.c
@@ -70,6 +70,10 @@ extern int errno;
 #endif /* !STREQ */
 #define STRCOLLEQ(a, b) ((a)[0] == (b)[0] && strcoll ((a), (b)) == 0)
 
+/* Same as ISOPTION from builtins/common.h */
+#define ISPRIMARY(s, c)        (s[0] == '-' && s[1] == c && s[2] == '\0')
+#define ANDOR(s)  (s[0] == '-' && (s[1] == 'a' || s[1] == 'o') && s[2] == 0)
+
 #if !defined (R_OK)
 #define R_OK 4
 #define W_OK 2
@@ -184,7 +188,7 @@ or (void)
   int value, v2;
 
   value = and ();
-  if (pos < argc && argv[pos][0] == '-' && argv[pos][1] == 'o' && !argv[pos][2])
+  if (pos < argc && ISPRIMARY (argv[pos], 'o'))
     {
       advance (0);
       v2 = or ();
@@ -205,7 +209,7 @@ and (void)
   int value, v2;
 
   value = term ();
-  if (pos < argc && argv[pos][0] == '-' && argv[pos][1] == 'a' && !argv[pos][2])
+  if (pos < argc && ISPRIMARY (argv[pos], 'a'))
     {
       advance (0);
       v2 = and ();
@@ -477,7 +481,7 @@ unary_operator (void)
     return (FALSE);
 
   /* the only tricky case is `-t', which may or may not take an argument. */
-  if (op[1] == 't')
+  if (posixly_correct == 0 && op[1] == 't')
     {
       advance (0);
       if (pos < argc)
@@ -487,10 +491,13 @@ unary_operator (void)
              advance (0);
              return (unary_test (op, argv[pos - 1], 0));
            }
+         else if (argc >= 5 && ANDOR (argv[pos]))
+           return (unary_test (op, "1", 0));     
          else
-           return (FALSE);
+           integer_expected_error (argv[pos]);
        }
       else
+       /* this is not called when pos == argc; the one-argument code is used */
        return (unary_test (op, "1", 0));
     }
 
@@ -603,7 +610,7 @@ unary_test (char *op, char *arg, int flags)
 
     case 't':  /* File fd is a terminal? */
       if (legal_number (arg, &r) == 0)
-       return (FALSE);
+       integer_expected_error (arg);
       return ((r == (int)r) && isatty ((int)r));
 
     case 'n':                  /* True if arg has some length. */
@@ -762,8 +769,6 @@ two_arguments (void)
   return (0);
 }
 
-#define ANDOR(s)  (s[0] == '-' && (s[1] == 'a' || s[1] == 'o') && s[2] == 0)
-
 /* This could be augmented to handle `-t' as equivalent to `-t 1', but
    POSIX requires that `-t' be given an argument. */
 #define ONE_ARG_TEST(s)                ((s)[0] != '\0')
index daf2f532e63a163239275192f8688c6a9367137f..0927ad086c5f3959f626437bf4d3806e75ba1469 100644 (file)
@@ -279,18 +279,24 @@ b ( 1 = 2
 ./test.tests: line 26: test: (: unary operator expected
 2
 t -t a
-1
+./test.tests: line 26: test: a: integer expected
+2
 t -t addsds
-1
+./test.tests: line 26: test: addsds: integer expected
+2
 t -t 42
 1
 t -t /dev/tty
-1
+./test.tests: line 26: test: /dev/tty: integer expected
+2
 t -t /dev/tty4
-1
+./test.tests: line 26: test: /dev/tty4: integer expected
+2
 t -t /dev/tty4444444...
-1
-1
+./test.tests: line 26: test: /dev/tty4444444...: integer expected
+2
+./test.tests: line 26: test:  : integer expected
+2
 t -p /dev/fd/6
 1
 t -p /dev/fd/6
index 0fde5b20decd90243c0c83ab516e925dd328739c..138c869a6436dab4fd8c161070ae54280b5803d7 100644 (file)
@@ -49,6 +49,10 @@ fff
 x=10 fff
 x=1 fff
 x=4 fff2
+# set this because variable assignments preceding functions should never
+# persist after the function returns, no matter what a builtin inside the
+# function does to them
+x=4
 x=11 fff3
 echo after fff3: x=$x
 x=12 fff4