Skip to content

Commit b98d3c4

Browse files
cgzonesfishilico
authored andcommitted
libsepol: do not pass NULL to memcpy
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 <[email protected]>
1 parent 7f600c4 commit b98d3c4

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

libsepol/src/link.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,9 @@ static int permission_copy_callback(hashtab_key_t key, hashtab_datum_t datum,
190190
ERR(state->handle, "Out of memory!");
191191
return -1;
192192
}
193-
memcpy(newmap, mod->perm_map[sclassi],
194-
mod->perm_map_len[sclassi] * sizeof(*newmap));
193+
if (mod->perm_map_len[sclassi] > 0) {
194+
memcpy(newmap, mod->perm_map[sclassi], mod->perm_map_len[sclassi] * sizeof(*newmap));
195+
}
195196
free(mod->perm_map[sclassi]);
196197
mod->perm_map[sclassi] = newmap;
197198
mod->perm_map_len[sclassi] = perm->s.value;

0 commit comments

Comments
 (0)