diff mbox series

[RFC,4/9] mcstrans: check getcon(3) and context_range_set(3) for failure

Message ID 20230512102322.72235-4-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
mcstrans.c: In function ‘new_context_str’:
    mcstrans.c:926:9: error: ignoring return value of ‘context_range_set’ declared with attribute ‘warn_unused_result’ [-Werror=unused-result]
      926 |         context_range_set(con, range);
          |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    mcscolor.c: In function ‘init_colors’:
    mcscolor.c:252:9: error: ignoring return value of ‘getcon’ declared with attribute ‘warn_unused_result’ [-Werror=unused-result]
      252 |         getcon(&my_context);
          |         ^~~~~~~~~~~~~~~~~~~

Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
---
 mcstrans/src/mcscolor.c | 3 ++-
 mcstrans/src/mcstrans.c | 5 ++++-
 2 files changed, 6 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/mcstrans/src/mcscolor.c b/mcstrans/src/mcscolor.c
index 9ff0ce2f..7d8f676e 100644
--- a/mcstrans/src/mcscolor.c
+++ b/mcstrans/src/mcscolor.c
@@ -249,7 +249,8 @@  int init_colors(void) {
 	char *buffer = NULL;
 	int line = 0;
 
-	getcon(&my_context);
+	if (getcon(&my_context) < 0)
+		return 1;
 
 	cfg = fopen(selinux_colors_path(), "r");
 	if (!cfg) return 1;
diff --git a/mcstrans/src/mcstrans.c b/mcstrans/src/mcstrans.c
index af3f507e..34dceca5 100644
--- a/mcstrans/src/mcstrans.c
+++ b/mcstrans/src/mcstrans.c
@@ -923,7 +923,10 @@  new_context_str(const char *incon, const char *range) {
 	if (!con) {
 		goto exit;
 	}
-	context_range_set(con, range);
+	if (context_range_set(con, range) < 0) {
+		context_free(con);
+		goto exit;
+	}
 	rcon = strdup(context_str(con));
 	context_free(con);
 	if (!rcon) {