From 6e4bb702af6a77dba2c646a9563899243ad5ebd5 Mon Sep 17 00:00:00 2001 From: Stephen Smalley Date: Wed, 2 Nov 2016 09:58:54 -0400 Subject: [PATCH] mcstrans: fix clang warnings Fix the following warnings from clang. mcstrans.c:1309:6: warning: variable 'groups' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized] if (violates_constraints(l)) { ^~~~~~~~~~~~~~~~~~~~~~~ mcstrans.c:1491:9: note: uninitialized use occurs here while (groups) ^~~~~~ mcstrans.c:1309:2: note: remove the 'if' if its condition is always false if (violates_constraints(l)) { ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ mcstrans.c:1303:6: warning: variable 'groups' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized] if (!l) ^~ mcstrans.c:1491:9: note: uninitialized use occurs here while (groups) ^~~~~~ mcstrans.c:1303:2: note: remove the 'if' if its condition is always false if (!l) ^~~~~~~ mcstrans.c:1299:6: warning: variable 'groups' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized] if (!level) ^~~~~~ mcstrans.c:1491:9: note: uninitialized use occurs here while (groups) ^~~~~~ mcstrans.c:1299:2: note: remove the 'if' if its condition is always false if (!level) ^~~~~~~~~~~ mcstrans.c:1316:2: note: variable 'groups' is declared here word_group_t *groups = NULL; ^ 3 warnings generated. mcscolor.c:334:24: warning: size argument in 'strncat' call appears to be size of the source [-Wstrncat-size] strncat(result, buf, sizeof(buf)); Signed-off-by: Stephen Smalley --- mcstrans/src/mcscolor.c | 5 +++-- mcstrans/src/mcstrans.c | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/mcstrans/src/mcscolor.c b/mcstrans/src/mcscolor.c index 66f99d2e..558c2a0e 100644 --- a/mcstrans/src/mcscolor.c +++ b/mcstrans/src/mcscolor.c @@ -289,6 +289,7 @@ int raw_color(const security_context_t raw, char **color_str) { const secolor_t *items[N_COLOR]; char *result, *components[N_COLOR]; char buf[CHARS_PER_COLOR + 1]; + size_t result_size = (N_COLOR * CHARS_PER_COLOR) + 1; int rc = -1; if (!color_str && !*color_str) { @@ -302,7 +303,7 @@ int raw_color(const security_context_t raw, char **color_str) { if (parse_components(con, components) < 0) goto out; - result = malloc((N_COLOR * CHARS_PER_COLOR) + 1); + result = malloc(result_size); if (!result) goto out; result[0] = '\0'; @@ -331,7 +332,7 @@ int raw_color(const security_context_t raw, char **color_str) { for (i = 0; i < N_COLOR; i++) { snprintf(buf, sizeof(buf), "#%06x #%06x ", items[i]->fg, items[i]->bg); - strncat(result, buf, sizeof(buf)); + strncat(result, buf, result_size-1); } *color_str = result; diff --git a/mcstrans/src/mcstrans.c b/mcstrans/src/mcstrans.c index 4d318576..d7f094a0 100644 --- a/mcstrans/src/mcstrans.c +++ b/mcstrans/src/mcstrans.c @@ -1287,6 +1287,7 @@ compute_trans_from_raw(const char *level, domain_t *domain) { mls_level_t *l = NULL; char *rval = NULL; + word_group_t *groups = NULL; ebitmap_t bit_diff, temp, handled, nothandled, unhandled, orig_unhandled; ebitmap_init(&bit_diff); @@ -1313,7 +1314,6 @@ compute_trans_from_raw(const char *level, domain_t *domain) { int doInverse = l->sens > 0; - word_group_t *groups = NULL; base_classification_t *bc, *last = NULL; int done = 0; for (bc = domain->base_classifications; bc && !done; bc = bc->next) {