Note: This is a public test instance of Red Hat Bugzilla. The data contained within is a snapshot of the live data so any changes you make will not be reflected in the production Bugzilla. Email is disabled so feel free to test any aspect of the site that you want. File any problems you find or give feedback at bugzilla.redhat.com.
Bug 1389838 - command builtin should not abort on variable assignment errors
Summary: command builtin should not abort on variable assignment errors
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Fedora
Classification: Fedora
Component: bash
Version: 26
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
Assignee: Siteshwar Vashisht
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2016-10-28 20:19 UTC by Denys Vlasenko
Modified: 2017-06-09 19:15 UTC (History)
3 users (show)

Fixed In Version: bash-4.4.12-5.fc26
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2017-06-09 19:15:24 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)

Description Denys Vlasenko 2016-10-28 20:19:25 UTC
Shell has a concept of "special builtin utilities":
builtins which are special have a few properties which are different from the builtins which are merely optimizations (for example, "echo" builtin is not special, it is an optimization: we don't want to fork an entire process in order to print a few bytes).

In particular:
http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html
"2.14. Special Built-In Utilities
...
A syntax error in a special built-in utility may cause a shell executing that utility to abort, while a syntax error in a regular built-in utility shall not cause a shell executing that utility to abort."

However.

There is a (regular, non-special) builtin, "command":
http://pubs.opengroup.org/onlinepubs/9699919799/utilities/command.html
which is required to "nullify" this effect:
"If the command_name is the same as the name of one of the special built-in utilities, the special properties in the enumerated list at the beginning of 'Special Built-In Utilities' shall not occur."

The bug is that in Posix mode (for example, if called as "sh", not "bash"), bash aborts in this example:

sh -c 'readonly VAR=123; command eval "VAR=123"; echo $?'

The bug is that "echo $?" command is not executed: shell aborted execution before reaching it.

There exist scripts which use this construct to detect whether a given variable is read-only.

Comment 1 Fedora End Of Life 2017-02-28 10:31:39 UTC
This bug appears to have been reported against 'rawhide' during the Fedora 26 development cycle.
Changing version to '26'.

Comment 3 Siteshwar Vashisht 2017-04-28 13:55:36 UTC
diff --git a/subst.c b/subst.c
index 65e7d08..998b850 100644
--- a/subst.c
+++ b/subst.c
@@ -10863,11 +10863,12 @@ expand_word_list_internal (list, eflags)
                  tint = do_word_assignment (temp_list->word, 0);
                  this_command_name = savecmd;
                  /* Variable assignment errors in non-interactive shells
-                    running in Posix.2 mode cause the shell to exit. */
+                    running in Posix.2 mode cause the shell to exit, unless
+                    they are being run by the `command' builtin. */
                  if (tint == 0)
                    {
                      last_command_exit_value = EXECUTION_FAILURE;
-                     if (interactive_shell == 0 && posixly_correct)
+                     if (interactive_shell == 0 && posixly_correct && executing_command_builtin == 0)
                        exp_jump_to_top_level (FORCE_EOF);
                      else
                        exp_jump_to_top_level (DISCARD);

Comment 4 Fedora Update System 2017-05-30 05:40:50 UTC
bash-4.4.12-5.fc26 has been submitted as an update to Fedora 26. https://bodhi.fedoraproject.org/updates/FEDORA-2017-84add424bf

Comment 5 Fedora Update System 2017-05-30 21:46:52 UTC
bash-4.4.12-5.fc26 has been pushed to the Fedora 26 testing repository. If problems still persist, please make note of it in this bug report.
See https://fedoraproject.org/wiki/QA:Updates_Testing for
instructions on how to install test updates.
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2017-84add424bf

Comment 6 Fedora Update System 2017-06-09 19:15:24 UTC
bash-4.4.12-5.fc26 has been pushed to the Fedora 26 stable repository. If problems still persist, please make note of it in this bug report.


Note You need to log in before you can comment on or make changes to this bug.