Skip to content

Commit

Permalink
checkpolicy: avoid assigning garbage values
Browse files Browse the repository at this point in the history
Only assign the computed value on success, since it is not set by
declare_symbol() on failure.

Reported by GCC:

    module_compiler.c: In function 'create_role':
    module_compiler.c:287:24: warning: use of uninitialized value 'value' [CWE-457] [-Wanalyzer-use-of-uninitialized-value]
      287 |         datum->s.value = value;
          |         ~~~~~~~~~~~~~~~^~~~~~~

Signed-off-by: Christian Göttsche <[email protected]>
Acked-by: James Carter <[email protected]>
  • Loading branch information
cgzones authored and jwcart2 committed Mar 4, 2024
1 parent 63207ce commit 22f7bb8
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions checkpolicy/module_compiler.c
Original file line number Diff line number Diff line change
Expand Up @@ -284,9 +284,8 @@ static int create_role(uint32_t scope, unsigned char isattr, role_datum_t **role
ret = require_symbol(SYM_ROLES, id, datum, &value, &value);
}

datum->s.value = value;

if (ret == 0) {
datum->s.value = value;
*role = datum;
*key = strdup(id);
if (*key == NULL) {
Expand All @@ -303,6 +302,7 @@ static int create_role(uint32_t scope, unsigned char isattr, role_datum_t **role
free(datum);
return -1;
}
datum->s.value = value;
*role = datum;
*key = id;
} else {
Expand Down Expand Up @@ -529,16 +529,16 @@ static int create_user(uint32_t scope, user_datum_t **user, char **key)
ret = require_symbol(SYM_USERS, id, datum, &value, &value);
}

datum->s.value = value;

if (ret == 0) {
datum->s.value = value;
*user = datum;
*key = strdup(id);
if (*key == NULL) {
yyerror("Out of memory!");
return -1;
}
} else if (ret == 1) {
datum->s.value = value;
*user = datum;
*key = id;
} else {
Expand Down

0 comments on commit 22f7bb8

Please sign in to comment.