From patchwork Wed Nov 26 19:00:33 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joseph Myers X-Patchwork-Id: 3956 Received: (qmail 23607 invoked by alias); 26 Nov 2014 19:00:40 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 23585 invoked by uid 89); 26 Nov 2014 19:00:39 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 X-HELO: relay1.mentorg.com Date: Wed, 26 Nov 2014 19:00:33 +0000 From: Joseph Myers To: Subject: Avoid warnings for unused results in nscd/connections.c Message-ID: User-Agent: Alpine 2.10 (DEB 1266 2009-07-14) MIME-Version: 1.0 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 . (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 * 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"),