bug#79780: Resource leak in change_file_context() in src/chcon.c (coreutils Latest)

Ray steven <[email protected]>
Newsgroups gmane.comp.gnu.core-utils.bugs
Message-ID <CAC2RF+MoNJYeON=uxcL9qH9jxZyVTAJhmnzQettwJqSyAmGGog@mail.gmail.com>
Subject: [BUG] Resource leak in change_file_context() in src/chcon.c
(coreutils 9.x)

Hello Coreutils maintainers,

I discovered a potential resource leak at lines 170-171 in the function
`change_file_context()` in `src/chcon.c`.

Bug Summary
------------
A resource leak occurs when `specified_context` is NULL and
`compute_context_from_mask()` fails. In this error path, the previously
obtained `file_context` (via `getfileconat()` or `lgetfileconat()`) is not
released, resulting in a memory leak. According to the official
documentation, the caller must use `freecon()` to manually release the
memory returned by `getfileconat()` or `lgetfileconat()`.

Suggested Fix
-------------
Call `freecon(file_context);` before returning when
`compute_context_from_mask()` fails. For example:

    if (compute_context_from_mask(file_context, &context) != 0)
    {
        freecon(file_context);
        return 1;
    }

Thanks for your time and for maintaining Coreutils.

Best regards,
CheckScope
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.