Skip to content

Commit fe7021b

Browse files
committed
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). Use a realloc + memset instead of a calloc and free to increase the size of `mod->perm_map[sclassi]`. Signed-off-by: Christian Göttsche <[email protected]>
1 parent 019cdbf commit fe7021b

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

libsepol/src/link.c

+2-4
Original file line numberDiff line numberDiff line change
@@ -185,14 +185,12 @@ static int permission_copy_callback(hashtab_key_t key, hashtab_datum_t datum,
185185
* may have originated from the class -or- it could be from
186186
* the class's common parent.*/
187187
if (perm->s.value > mod->perm_map_len[sclassi]) {
188-
uint32_t *newmap = calloc(perm->s.value, sizeof(*newmap));
188+
uint32_t *newmap = realloc(mod->perm_map[sclassi], perm->s.value * sizeof(*newmap));
189189
if (newmap == NULL) {
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));
195-
free(mod->perm_map[sclassi]);
193+
memset(newmap + mod->perm_map_len[sclassi], '\0', perm->s.value - mod->perm_map_len[sclassi]);
196194
mod->perm_map[sclassi] = newmap;
197195
mod->perm_map_len[sclassi] = perm->s.value;
198196
}

0 commit comments

Comments
 (0)