selinux: fix potential segfault in sestatus

Remove the puts(cterm) call that was likely leftover debugging code.
The controlling terminal name is already properly displayed via the
'Controlling term:' label, so the raw terminal name output was redundant
and could cause issues when cterm is NULL.

Also add proper cleanup for the allocated cterm string.

function                                             old     new   delta
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/0 up/down: 0/0)                 Total: 0 bytes

Signed-off-by: Osama Abdelkader <osama.abdelkader@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko 2025-10-07 08:36:40 +02:00
parent 9443b0bc5e
commit 552003dbd6

View file

@ -131,13 +131,13 @@ static void display_verbose(void)
puts("\nFile contexts:");
cterm = xmalloc_ttyname(0);
//FIXME: if cterm == NULL, we segfault!??
puts(cterm);
if (cterm && lgetfilecon(cterm, &con) >= 0) {
printf(COL_FMT "%s\n", "Controlling term:", con);
if (ENABLE_FEATURE_CLEAN_UP)
freecon(con);
}
if (ENABLE_FEATURE_CLEAN_UP)
free(cterm);
for (i = 0; fc[i] != NULL; i++) {
struct stat stbuf;