Skip to contentSkip to conversation

mcstrans: Fix check in raw_color()

PATCH In review Petr Lautrbach 2 participants 2 messages Dec 19, 2018 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mcstrans: Fix check in raw_color()

raw_color() uses color_str as an output argument which is assigned to a new allocated memory. Therefore it should fail when color_str is null; or when *color_str is not null in order to avoid a memory leak.

Fixes:

Quoted 1 line
Quoted 1 line
Quoted 1 line

selinux.selinux_raw_context_to_color('system_u:system_r:inetd_t:s0')

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
OSError: [Errno 0] Error

---
 mcstrans/src/mcscolor.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mcstrans/src/mcscolor.c +1 -1
index cc6174bb..6ea1aa97 100644
@@ -292,7 +292,7 @@ int raw_color(const security_context_t raw, char **color_str) {
 	size_t result_size = (N_COLOR * CHARS_PER_COLOR) + 1;
 	int rc = -1;
 
-	if (!color_str || !*color_str) {
+	if (!color_str || *color_str) {
 		return -1;
 	}
 
Signature · 1 line
2.20.0
Acked-by on v1 1/1
#1 lore raw
Quoted 5 lines · Petr Lautrbach

raw_color() uses color_str as an output argument which is assigned to a new allocated memory. Therefore it should fail when color_str is null; or when *color_str is not null in order to avoid a memory leak.

Quoted 7 lines

Fixes:

Quoted 1 line
Quoted 1 line
Quoted 1 line

selinux.selinux_raw_context_to_color('system_u:system_r:inetd_t:s0')

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
OSError: [Errno 0] Error

Quoted 20 lines
---
 mcstrans/src/mcscolor.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mcstrans/src/mcscolor.c +1 -2
index cc6174bb..6ea1aa97 100644
@@ -292,7 +292,7 @@ int raw_color(const security_context_t raw, char **color_str) {
        size_t result_size = (N_COLOR * CHARS_PER_COLOR) + 1;
        int rc = -1;
 
-       if (!color_str || !*color_str) {
+       if (!color_str || *color_str) {
                return -1;
        }
 
--

2.20.0