Skip to content

Commit 760d76b

Browse files
committed
mcstrans: check getcon(3) and context_range_set(3) for failure
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 <[email protected]>
1 parent a3e7a13 commit 760d76b

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

mcstrans/src/mcscolor.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,8 @@ int init_colors(void) {
249249
char *buffer = NULL;
250250
int line = 0;
251251

252-
getcon(&my_context);
252+
if (getcon(&my_context) < 0)
253+
return 1;
253254

254255
cfg = fopen(selinux_colors_path(), "r");
255256
if (!cfg) return 1;

mcstrans/src/mcstrans.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -923,7 +923,10 @@ new_context_str(const char *incon, const char *range) {
923923
if (!con) {
924924
goto exit;
925925
}
926-
context_range_set(con, range);
926+
if (context_range_set(con, range) < 0) {
927+
context_free(con);
928+
goto exit;
929+
}
927930
rcon = strdup(context_str(con));
928931
context_free(con);
929932
if (!rcon) {

0 commit comments

Comments
 (0)