All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Christian Göttsche" <cgzones@googlemail.com>
To: selinux@vger.kernel.org
Subject: [PATCH 09/13] checkpolicy: avoid potential use of uninitialized variable
Date: Tue,  6 Jul 2021 19:54:29 +0200	[thread overview]
Message-ID: <20210706175433.29270-9-cgzones@googlemail.com> (raw)
In-Reply-To: <20210706175433.29270-1-cgzones@googlemail.com>

    checkpolicy.c: In function ‘main’:
    checkpolicy.c:1000:25: error: ‘tsid’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
     1000 |                         printf("if_sid %d default_msg_sid %d\n", ssid, tsid);
          |                         ^

    checkpolicy.c: In function ‘main’:
    checkpolicy.c:971:25: error: ‘tsid’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
      971 |                         printf("fs_sid %d default_file_sid %d\n", ssid, tsid);
          |                         ^

Found by GCC 11 with LTO enabled.

Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
---
 checkpolicy/checkpolicy.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/checkpolicy/checkpolicy.c b/checkpolicy/checkpolicy.c
index c88ca542..04f35eda 100644
--- a/checkpolicy/checkpolicy.c
+++ b/checkpolicy/checkpolicy.c
@@ -967,8 +967,12 @@ int main(int argc, char **argv)
 			printf("fs kdevname?  ");
 			FGETS(ans, sizeof(ans), stdin);
 			ans[strlen(ans) - 1] = 0;
-			sepol_fs_sid(ans, &ssid, &tsid);
-			printf("fs_sid %d default_file_sid %d\n", ssid, tsid);
+			ret = sepol_fs_sid(ans, &ssid, &tsid);
+			if (ret) {
+				printf("unknown fs kdevname\n");
+			} else {
+				printf("fs_sid %d default_file_sid %d\n", ssid, tsid);
+			}
 			break;
 		case '9':
 			printf("protocol?  ");
@@ -996,8 +1000,12 @@ int main(int argc, char **argv)
 			printf("netif name?  ");
 			FGETS(ans, sizeof(ans), stdin);
 			ans[strlen(ans) - 1] = 0;
-			sepol_netif_sid(ans, &ssid, &tsid);
-			printf("if_sid %d default_msg_sid %d\n", ssid, tsid);
+			ret = sepol_netif_sid(ans, &ssid, &tsid);
+			if (ret) {
+				printf("unknown name\n");
+			} else {
+				printf("if_sid %d default_msg_sid %d\n", ssid, tsid);
+			}
 			break;
 		case 'b':{
 				char *p;
-- 
2.32.0


  parent reply	other threads:[~2021-07-06 17:54 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-06 17:54 [PATCH 01/13] checkpolicy: pass CFLAGS at link stage Christian Göttsche
2021-07-06 17:54 ` [PATCH 02/13] checkpolicy: drop -pipe compile option Christian Göttsche
2021-07-06 17:54 ` [PATCH 03/13] checkpolicy: simplify assignment Christian Göttsche
2021-07-06 17:54 ` [PATCH 04/13] checkpolicy: drop dead condition Christian Göttsche
2021-07-06 17:54 ` [PATCH 05/13] checkpolicy: use correct format specifier for unsigned Christian Göttsche
2021-07-06 17:54 ` [PATCH 06/13] checkpolicy: follow declaration-after-statement Christian Göttsche
2021-07-12  7:13   ` Nicolas Iooss
2021-07-13 19:59     ` Nicolas Iooss
2021-07-06 17:54 ` [PATCH 07/13] checkpolicy: remove dead assignments Christian Göttsche
2021-07-06 17:54 ` [PATCH 08/13] checkpolicy: check before potential NULL dereference Christian Göttsche
2021-07-06 17:54 ` Christian Göttsche [this message]
2021-07-06 17:54 ` [PATCH 10/13] checkpolicy: drop redundant cast to the same type Christian Göttsche
2021-07-06 17:54 ` [PATCH 11/13] checkpolicy: parse_util drop unused declaration Christian Göttsche
2021-07-06 17:54 ` [PATCH 12/13] checkpolicy/test: mark file local functions static Christian Göttsche
2021-07-06 17:54 ` [PATCH 13/13] checkpolicy: mark read-only parameters in policy define const Christian Göttsche

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210706175433.29270-9-cgzones@googlemail.com \
    --to=cgzones@googlemail.com \
    --cc=selinux@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.