diff mbox series

[RFC,7/9] secon: check selinux_raw_to_trans_context(3) for failure

Message ID 20230512102322.72235-7-cgzones@googlemail.com (mailing list archive)
State New, archived
Delegated to: Petr Lautrbach
Headers show
Series [RFC,1/9] libselinux: annotate interfaces with compiler attributes | expand

Commit Message

Christian Göttsche May 12, 2023, 10:23 a.m. UTC
secon.c: In function ‘disp_con’:
    secon.c:634:9: error: ignoring return value of ‘selinux_raw_to_trans_context’ declared with attribute ‘warn_unused_result’ [-Werror=unused-result]
      634 |         selinux_raw_to_trans_context(scon_raw, &scon_trans);
          |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
---
 policycoreutils/secon/secon.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/policycoreutils/secon/secon.c b/policycoreutils/secon/secon.c
index d624fa13..82266894 100644
--- a/policycoreutils/secon/secon.c
+++ b/policycoreutils/secon/secon.c
@@ -2,7 +2,7 @@ 
 #include <stdlib.h>
 #include <stdio.h>
 #include <assert.h>
-
+#include <errno.h>
 #include <string.h>
 
 #define xstreq(x, y) !strcmp(x, y)
@@ -631,7 +631,10 @@  static void disp_con(const char *scon_raw)
 	char *color_str = NULL;
 	struct context_color_t color = { .valid = 0 };
 
-	selinux_raw_to_trans_context(scon_raw, &scon_trans);
+	if (selinux_raw_to_trans_context(scon_raw, &scon_trans) < 0)
+		errx(EXIT_FAILURE, "Couldn't convert context %s:  %s",
+		     scon_raw, strerror(errno));
+
 	if (opts->disp_raw)
 		scon = scon_raw;
 	else