public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* Avoid warnings for unused results in nscd/connections.c
@ 2014-11-26 19:00 Joseph Myers
  2014-11-26 19:19 ` Paul Eggert
  2014-11-27  8:24 ` Stefan Liebler
  0 siblings, 2 replies; 4+ messages in thread
From: Joseph Myers @ 2014-11-26 19:00 UTC (permalink / raw)
  To: libc-alpha

This patch avoids warnings for unused results of setuid and setgid in
nscd/connections.c using an ignore_value macro along the lines
suggested by Paul in
<https://sourceware.org/ml/libc-alpha/2014-11/msg00733.html>.

(If anyone thinks the return values should not be ignored - that
ignoring them is a bug, whether security or otherwise - please file
that bug in Bugzilla.  Having the warnings around hasn't done any good
to get any such bug fixed, and it's not useful for any such bug to
block use of -Werror.)

Tested for x86_64.

2014-11-26  Joseph Myers  <joseph@codesourcery.com>

	* include/libc-internal.h (ignore_value): New macro.
	* nscd/connections.c (restart): Wrap calls to setuid and setgid
	with ignore_value.

diff --git a/include/libc-internal.h b/include/libc-internal.h
index 78f82da..2ced1c1 100644
--- a/include/libc-internal.h
+++ b/include/libc-internal.h
@@ -70,4 +70,10 @@ extern void __init_misc (int, char **, char **);
 #define PTR_ALIGN_UP(base, size) \
   ((__typeof__ (base)) ALIGN_UP ((uintptr_t) (base), (size)))
 
+/* Ignore the value of an expression when a cast to void does not
+   suffice (in particular, for a call to a function declared with
+   attribute warn_unused_result).  */
+#define ignore_value(x) \
+  ({ __typeof__ (x) __ignored_value = (x); (void) __ignored_value; })
+
 #endif /* _LIBC_INTERNAL  */
diff --git a/nscd/connections.c b/nscd/connections.c
index 3e950af..1631212 100644
--- a/nscd/connections.c
+++ b/nscd/connections.c
@@ -1464,7 +1464,7 @@ cannot change to old UID: %s; disabling paranoia mode"),
 cannot change to old GID: %s; disabling paranoia mode"),
 		   strerror (errno));
 
-	  setuid (server_uid);
+	  ignore_value (setuid (server_uid));
 	  paranoia = 0;
 	  return;
 	}
@@ -1479,8 +1479,8 @@ cannot change to old working directory: %s; disabling paranoia mode"),
 
       if (server_user != NULL)
 	{
-	  setuid (server_uid);
-	  setgid (server_gid);
+	  ignore_value (setuid (server_uid));
+	  ignore_value (setgid (server_gid));
 	}
       paranoia = 0;
       return;
@@ -1524,8 +1524,8 @@ cannot change to old working directory: %s; disabling paranoia mode"),
 
   if (server_user != NULL)
     {
-      setuid (server_uid);
-      setgid (server_gid);
+      ignore_value (setuid (server_uid));
+      ignore_value (setgid (server_gid));
     }
   if (chdir ("/") != 0)
     dbg_log (_("cannot change current working directory to \"/\": %s"),

-- 
Joseph S. Myers
joseph@codesourcery.com

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

* Re: Avoid warnings for unused results in nscd/connections.c
  2014-11-26 19:00 Avoid warnings for unused results in nscd/connections.c Joseph Myers
@ 2014-11-26 19:19 ` Paul Eggert
  2014-11-27  8:24 ` Stefan Liebler
  1 sibling, 0 replies; 4+ messages in thread
From: Paul Eggert @ 2014-11-26 19:19 UTC (permalink / raw)
  To: Joseph Myers, libc-alpha

Thank you, this looks good.

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

* Re: Avoid warnings for unused results in nscd/connections.c
  2014-11-26 19:00 Avoid warnings for unused results in nscd/connections.c Joseph Myers
  2014-11-26 19:19 ` Paul Eggert
@ 2014-11-27  8:24 ` Stefan Liebler
  2014-11-27  9:06   ` Siddhesh Poyarekar
  1 sibling, 1 reply; 4+ messages in thread
From: Stefan Liebler @ 2014-11-27  8:24 UTC (permalink / raw)
  To: libc-alpha

[-- Attachment #1: Type: text/plain, Size: 517 bytes --]

Hi,

Building glibc fails at least on s390/power with:
connections.c: In function ‘restart’:
connections.c:1467:4: error: implicit declaration of function 
‘ignore_value’ [-Werror=implicit-function-declaration]
     ignore_value (setuid (server_uid));
     ^
cc1: some warnings being treated as errors

Including libc-internal.h fixes the build failure.

Bye
Stefan

---
2014-11-27  Stefan Liebler  <stli@linux.vnet.ibm.com>

	* nscd/connections.c: Include libc-internal.h
	  because of macro usage ignore_value.

[-- Attachment #2: 20141127_connections --]
[-- Type: text/plain, Size: 294 bytes --]

diff --git a/nscd/connections.c b/nscd/connections.c
index 1631212..a6b9808 100644
--- a/nscd/connections.c
+++ b/nscd/connections.c
@@ -59,6 +59,7 @@
 #include <resolv/resolv.h>
 
 #include <kernel-features.h>
+#include <libc-internal.h>
 
 
 /* Support to run nscd as an unprivileged user */

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

* Re: Avoid warnings for unused results in nscd/connections.c
  2014-11-27  8:24 ` Stefan Liebler
@ 2014-11-27  9:06   ` Siddhesh Poyarekar
  0 siblings, 0 replies; 4+ messages in thread
From: Siddhesh Poyarekar @ 2014-11-27  9:06 UTC (permalink / raw)
  To: Stefan Liebler; +Cc: GNU C Library

On 27 November 2014 at 13:53, Stefan Liebler <stli@linux.vnet.ibm.com> wrote:
> Building glibc fails at least on s390/power with:
> connections.c: In function ‘restart’:
> connections.c:1467:4: error: implicit declaration of function ‘ignore_value’
> [-Werror=implicit-function-declaration]
>     ignore_value (setuid (server_uid));
>     ^
> cc1: some warnings being treated as errors
>
> Including libc-internal.h fixes the build failure.
>
> Bye
> Stefan
>
> ---
> 2014-11-27  Stefan Liebler  <stli@linux.vnet.ibm.com>
>
>         * nscd/connections.c: Include libc-internal.h
>           because of macro usage ignore_value.

libc-internal.h got included indirectly on x86_64 (via
sysdeps/x86_64/tls.h), which is why it worked there and not on other
architectures.  This fix is correct, please commit it.

Siddhesh
-- 
http://siddhesh.in

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

end of thread, other threads:[~2014-11-27  9:06 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-11-26 19:00 Avoid warnings for unused results in nscd/connections.c Joseph Myers
2014-11-26 19:19 ` Paul Eggert
2014-11-27  8:24 ` Stefan Liebler
2014-11-27  9:06   ` Siddhesh Poyarekar

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 read-only IMAP folder(s) and NNTP newsgroup(s).