Skip to content

Commit

Permalink
libsepol: do not pass NULL to memcpy
Browse files Browse the repository at this point in the history
For the first iteration `mod->perm_map[sclassi]` is NULL, thus do not
use it as source of a memcpy(3), even with a size of 0.  memcpy(3) might
be annotated with the function attribute nonnull and UBSan then
complains:

    link.c:193:3: runtime error: null pointer passed as argument 2, which is declared to never be null

Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
  • Loading branch information
cgzones authored and fishilico committed Nov 11, 2021
1 parent 7f600c4 commit b98d3c4
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions libsepol/src/link.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,9 @@ static int permission_copy_callback(hashtab_key_t key, hashtab_datum_t datum,
ERR(state->handle, "Out of memory!");
return -1;
}
memcpy(newmap, mod->perm_map[sclassi],
mod->perm_map_len[sclassi] * sizeof(*newmap));
if (mod->perm_map_len[sclassi] > 0) {
memcpy(newmap, mod->perm_map[sclassi], mod->perm_map_len[sclassi] * sizeof(*newmap));
}
free(mod->perm_map[sclassi]);
mod->perm_map[sclassi] = newmap;
mod->perm_map_len[sclassi] = perm->s.value;
Expand Down

0 comments on commit b98d3c4

Please sign in to comment.