Skip to content

Commit

Permalink
40068: Abort execution when setuid/setgid fail.
Browse files Browse the repository at this point in the history
The incumbent code would print an error message and continue execution
with the previous uid/gid values, not even setting lastval:

    % UID=42 id -u; echo $?
    zsh: failed to change user ID: operation not permitted
    1000
    0
    %
  • Loading branch information
danielshahaf committed Dec 3, 2016
1 parent fd2ca22 commit 334ed65
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
3 changes: 3 additions & 0 deletions ChangeLog
@@ -1,5 +1,8 @@
2016-12-03 Daniel Shahaf <d.s@daniel.shahaf.name>

* 40068: Src/params.c, Test/B02typeset.ztst: Abort execution
when setuid/setgid fail.

* 40067: Src/Zle/comp.h, Src/Zle/complete.c, Src/params.c:
internal: Document 'cmatcher', parse_cmatcher(), 'comptoend',
unsetparam_pm(), and getindex().
Expand Down
8 changes: 4 additions & 4 deletions Src/params.c
Expand Up @@ -4077,7 +4077,7 @@ uidsetfn(UNUSED(Param pm), zlong x)
{
#ifdef HAVE_SETUID
if (setuid((uid_t)x))
zwarn("failed to change user ID: %e", errno);
zerr("failed to change user ID: %e", errno);
#endif
}

Expand All @@ -4098,7 +4098,7 @@ euidsetfn(UNUSED(Param pm), zlong x)
{
#ifdef HAVE_SETEUID
if (seteuid((uid_t)x))
zwarn("failed to change effective user ID: %e", errno);
zerr("failed to change effective user ID: %e", errno);
#endif
}

Expand All @@ -4119,7 +4119,7 @@ gidsetfn(UNUSED(Param pm), zlong x)
{
#ifdef HAVE_SETUID
if (setgid((gid_t)x))
zwarn("failed to change group ID: %e", errno);
zerr("failed to change group ID: %e", errno);
#endif
}

Expand All @@ -4140,7 +4140,7 @@ egidsetfn(UNUSED(Param pm), zlong x)
{
#ifdef HAVE_SETEUID
if (setegid((gid_t)x))
zwarn("failed to change effective group ID: %e", errno);
zerr("failed to change effective group ID: %e", errno);
#endif
}

Expand Down
10 changes: 10 additions & 0 deletions Test/B02typeset.ztst
Expand Up @@ -711,3 +711,13 @@
typeset isreadonly=still
1:typeset returns status 1 if setting readonly variable
?(eval):2: read-only variable: isreadonly

if (( UID )); then
UID=$((UID+1)) date; echo "Status is printed, $?"
else
ZTST_skip="cannot test setuid error when tests run as superuser"
fi
0:when cannot change UID, the command isn't run
# 'date' did not run.
>Status is printed, 1
?(eval):2: failed to change user ID: operation not permitted

0 comments on commit 334ed65

Please sign in to comment.