Skip to content

Commit

Permalink
libselinux/matchpathcon: RESOURCE_LEAK: Variable "con"
Browse files Browse the repository at this point in the history
Fixes:
 Error: RESOURCE_LEAK (CWE-772):
 libselinux-3.6/src/matchpathcon.c:519: alloc_arg: "lgetfilecon_raw" allocates memory that is stored into "con". [Note: The source code implementation of the function has been overridden by a user model.]
 libselinux-3.6/src/matchpathcon.c:528: leaked_storage: Variable "con" going out of scope leaks the storage it points to.
 \#  526|
 \#  527|           if (!hnd && (matchpathcon_init_prefix(NULL, NULL) < 0))
 \#  528|->                         return -1;
 \#  529|
 \#  530|           if (selabel_lookup_raw(hnd, &fcontext, path, mode) != 0) {

Signed-off-by: Vit Mojzis <[email protected]>
Acked-by: James Carter <[email protected]>
  • Loading branch information
vmojzis committed Nov 6, 2024
1 parent edce1de commit 48bfb96
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion libselinux/src/matchpathcon.c
Original file line number Diff line number Diff line change
Expand Up @@ -524,8 +524,10 @@ int selinux_file_context_verify(const char *path, mode_t mode)
return 0;
}

if (!hnd && (matchpathcon_init_prefix(NULL, NULL) < 0))
if (!hnd && (matchpathcon_init_prefix(NULL, NULL) < 0)){
freecon(con);
return -1;
}

if (selabel_lookup_raw(hnd, &fcontext, path, mode) != 0) {
if (errno != ENOENT)
Expand Down

0 comments on commit 48bfb96

Please sign in to comment.