Skip to content

Commit

Permalink
lib: Fix privs syscaps (pset_t) allocation
Browse files Browse the repository at this point in the history
Don't over-allocate syscaps in zcaps2sys(): This is just a single struct
(pset_t) with a count and a pointer to an array of capabilities, not an
array. So only allocate a single pset_t, not num copies of it.

The allocation size of syscaps->caps then needs to be based on the number of
Linux capabilities (count), but that is already handled properly a few lines
below.

Note that this fix is mostly cosmetic and for correctness. There was no
potential for memory corruption, because num is guaranteed to be nonzero. So
at least the one required pset_t was always allocated (but potentially much
more).

Signed-off-by: Martin Buck <[email protected]>
  • Loading branch information
gromit1811 committed Jan 8, 2025
1 parent 21fe1f4 commit 4ed9147
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/privs.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ static pset_t *zcaps2sys(zebra_capabilities_t *zcaps, int num)
for (i = 0; i < num; i++)
count += cap_map[zcaps[i]].num;

if ((syscaps = XCALLOC(MTYPE_PRIVS, (sizeof(pset_t) * num))) == NULL) {
if ((syscaps = XCALLOC(MTYPE_PRIVS, sizeof(pset_t))) == NULL) {
fprintf(stderr, "%s: could not allocate syscaps!", __func__);
return NULL;
}
Expand Down

0 comments on commit 4ed9147

Please sign in to comment.