Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib: Fix privs syscaps (pset_t) allocation #17795

Merged
merged 1 commit into from
Jan 8, 2025

Conversation

gromit1811
Copy link
Contributor

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).

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]>
@gromit1811
Copy link
Contributor Author

Stumbled over this while debugging #17775. Not a big deal, but would reduce confusion when reading the code 😉

@donaldsharp
Copy link
Member

LGTM. Once ci is successfull I will get this in

@donaldsharp donaldsharp merged commit 3d7dbcf into FRRouting:master Jan 8, 2025
14 checks passed
@gromit1811 gromit1811 deleted the bugfix_priv_syscaps_alloc branch January 9, 2025 08:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants