From patchwork Wed May 24 09:08:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Tremer X-Patchwork-Id: 6916 Return-Path: Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by web04.haj.ipfire.org (Postfix) with ESMTPS id 4QR52m3FCQz3wlp for ; Wed, 24 May 2023 09:08:48 +0000 (UTC) Received: from mail02.haj.ipfire.org (mail02.haj.ipfire.org [172.28.1.201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail02.haj.ipfire.org", Issuer "R3" (verified OK)) by mail01.ipfire.org (Postfix) with ESMTPS id 4QR52k6DpVzs0; Wed, 24 May 2023 09:08:46 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4QR52k4ZHPz2ydF; Wed, 24 May 2023 09:08:46 +0000 (UTC) Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by mail02.haj.ipfire.org (Postfix) with ESMTPS id 4QR52h5FJQz2xk2 for ; Wed, 24 May 2023 09:08:44 +0000 (UTC) Received: from michael.haj.ipfire.org (michael.haj.ipfire.org [172.28.1.242]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384 client-signature ECDSA (P-384) client-digest SHA384) (Client CN "michael.haj.ipfire.org", Issuer "R3" (verified OK)) by mail01.ipfire.org (Postfix) with ESMTPS id 4QR52f6DqbzjY; Wed, 24 May 2023 09:08:42 +0000 (UTC) Received: by michael.haj.ipfire.org (Postfix, from userid 0) id 4QR52f4KrxzThFj; Wed, 24 May 2023 09:08:42 +0000 (UTC) From: Michael Tremer To: development@lists.ipfire.org Subject: [PATCH] misc-progs: setuid: Return exit code from called process Date: Wed, 24 May 2023 09:08:41 +0000 Message-Id: <20230524090841.269580-1-michael.tremer@ipfire.org> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 X-BeenThere: development@lists.ipfire.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: IPFire development talk List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Tremer Errors-To: development-bounces@lists.ipfire.org Sender: "Development" This patch will return the exit code from the called process which has not been done before. This made it more difficult to catch any unsuccessful calls from the web UI. Partly Fixes: #12863 Tested-by: Jon Murphy Signed-off-by: Michael Tremer --- src/misc-progs/setuid.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/misc-progs/setuid.c b/src/misc-progs/setuid.c index 17b0e7066..9dc0a767b 100644 --- a/src/misc-progs/setuid.c +++ b/src/misc-progs/setuid.c @@ -104,16 +104,20 @@ static int system_core(char* command, char** args, uid_t uid, gid_t gid, char *e } default: /* parent */ - do { - if (waitpid(pid, &status, 0) == -1) { - if (errno != EINTR) - return -1; - } else { - return status; - } - } while (1); - } + // Wait until the child process has finished + waitpid(pid, &status, 0); + + // The child was terminated by a signal + if (WIFSIGNALED(status)) + return 128 + WTERMSIG(status); + // Return the exit code if available + if (WIFEXITED(status)) + return WEXITSTATUS(status); + + // Something unexpected happened, exiting with error + return EXIT_FAILURE; + } } int run(char* command, char** argv) {