SELinux Archive on lore.kernel.org
 help / Atom feed
* [PATCH] mcstrans: Fix check in raw_color()
@ 2018-12-19 11:45 Petr Lautrbach
  2018-12-19 21:44 ` Nicolas Iooss
  0 siblings, 1 reply; 2+ messages in thread
From: Petr Lautrbach @ 2018-12-19 11:45 UTC (permalink / raw)
  To: selinux; +Cc: 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.

Fixes:
>>> 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

Signed-off-by: Petr Lautrbach <plautrba@redhat.com>
---
 mcstrans/src/mcscolor.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mcstrans/src/mcscolor.c b/mcstrans/src/mcscolor.c
index cc6174bb..6ea1aa97 100644
--- a/mcstrans/src/mcscolor.c
+++ b/mcstrans/src/mcscolor.c
@@ -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


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] mcstrans: Fix check in raw_color()
  2018-12-19 11:45 [PATCH] mcstrans: Fix check in raw_color() Petr Lautrbach
@ 2018-12-19 21:44 ` Nicolas Iooss
  0 siblings, 0 replies; 2+ messages in thread
From: Nicolas Iooss @ 2018-12-19 21:44 UTC (permalink / raw)
  To: Petr Lautrbach; +Cc: selinux

On Wed, Dec 19, 2018 at 12:45 PM Petr Lautrbach <plautrba@redhat.com> wrote:
>
> 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:
> >>> 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
>
> Signed-off-by: Petr Lautrbach <plautrba@redhat.com>

Acked-by: Nicolas Iooss <nicolas.iooss@m4x.org>

> ---
>  mcstrans/src/mcscolor.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/mcstrans/src/mcscolor.c b/mcstrans/src/mcscolor.c
> index cc6174bb..6ea1aa97 100644
> --- a/mcstrans/src/mcscolor.c
> +++ b/mcstrans/src/mcscolor.c
> @@ -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
>


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-19 11:45 [PATCH] mcstrans: Fix check in raw_color() Petr Lautrbach
2018-12-19 21:44 ` Nicolas Iooss

SELinux Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/selinux/0 selinux/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 selinux selinux/ https://lore.kernel.org/selinux \
		selinux@vger.kernel.org selinux@archiver.kernel.org
	public-inbox-index selinux


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.selinux


AGPL code for this site: git clone https://public-inbox.org/ public-inbox