zsh-workers
 help / color / mirror / code / Atom feed
* [PATCH] Silence compilation warnings about setuid, setgid
@ 2018-05-07 11:18 Sebastian Gniazdowski
  2018-06-13 11:49 ` Eitan Adler
  0 siblings, 1 reply; 11+ messages in thread
From: Sebastian Gniazdowski @ 2018-05-07 11:18 UTC (permalink / raw)
  To: Zsh hackers list


[-- Attachment #1.1: Type: text/plain, Size: 1690 bytes --]

Hello,
on a Linux box I see:

options.c:772:2: warning: ignoring return value of ‘setuid’, declared with
attribute warn_unused_res
ult [-Wunused-result]
  setuid(getuid());
  ^~~~~~~~~~~~~~~~
options.c:773:2: warning: ignoring return value of ‘setgid’, declared with
attribute warn_unused_res
ult [-Wunused-result]
  setgid(getgid());
  ^~~~~~~~~~~~~~~~

Looking at the source, the reported calls are "extra" ones, they are
followed by proper setuid, setgid calls. I've found some way out from this
situation, of using the report value and reporting it (gmail paste, proper
patch is attached):

diff --git a/Src/options.c b/Src/options.c
index 590652ea9..e085af796 100644
--- a/Src/options.c
+++ b/Src/options.c
@@ -769,13 +769,23 @@ dosetopt(int optno, int value, int force, char
*new_opts)
     } else if(optno == PRIVILEGED && !value) {
        /* unsetting PRIVILEGED causes the shell to make itself
unprivileged */
 #ifdef HAVE_SETUID
-       setuid(getuid());
-       setgid(getgid());
+       int uerr = 0, gerr = 0;
+
+       if(setuid(getuid())) {
+           uerr = errno;
+       }
+       if(setgid(getgid())) {
+           gerr = errno;
+       }
         if (setuid(getuid())) {
             zwarn("failed to change user ID: %e", errno);
+            if (uerr)
+                zwarn("(error of additional preceding setuid() call: %e)",
uerr);
             return -1;
        } else if (setgid(getgid())) {
             zwarn("failed to change group ID: %e", errno);
+            if (gerr)
+                zwarn("(error of additional preceding setgid() call: %e)",
gerr);
             return -1;
         }
 #else

[-- Attachment #1.2: Type: text/html, Size: 2082 bytes --]

[-- Attachment #2: setuid.diff.txt --]
[-- Type: text/plain, Size: 968 bytes --]

diff --git a/Src/options.c b/Src/options.c
index 590652ea9..e085af796 100644
--- a/Src/options.c
+++ b/Src/options.c
@@ -769,13 +769,23 @@ dosetopt(int optno, int value, int force, char *new_opts)
     } else if(optno == PRIVILEGED && !value) {
 	/* unsetting PRIVILEGED causes the shell to make itself unprivileged */
 #ifdef HAVE_SETUID
-	setuid(getuid());
-	setgid(getgid());
+	int uerr = 0, gerr = 0;
+
+	if(setuid(getuid())) {
+	    uerr = errno;
+	}
+	if(setgid(getgid())) {
+	    gerr = errno;
+	}
         if (setuid(getuid())) {
             zwarn("failed to change user ID: %e", errno);
+            if (uerr)
+                zwarn("(error of additional preceding setuid() call: %e)", uerr);
             return -1;
 	} else if (setgid(getgid())) {
             zwarn("failed to change group ID: %e", errno);
+            if (gerr)
+                zwarn("(error of additional preceding setgid() call: %e)", gerr);
             return -1;
         }
 #else

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2018-06-14 10:40 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-07 11:18 [PATCH] Silence compilation warnings about setuid, setgid Sebastian Gniazdowski
2018-06-13 11:49 ` Eitan Adler
2018-06-13 13:10   ` Peter Stephenson
2018-06-13 15:08     ` Bart Schaefer
2018-06-13 15:16       ` Peter Stephenson
2018-06-13 17:13       ` Eitan Adler
2018-06-13 17:19         ` Peter Stephenson
2018-06-13 18:41           ` dana
2018-06-14  8:41             ` Peter Stephenson
2018-06-14 10:31               ` dana
2018-06-14 10:40                 ` Peter Stephenson

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).