selinux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] libselinux: Fix security_get_boolean_names build error
@ 2019-07-03 14:12 Richard Haines
  2019-07-07 21:02 ` Nicolas Iooss
  0 siblings, 1 reply; 4+ messages in thread
From: Richard Haines @ 2019-07-03 14:12 UTC (permalink / raw)
  To: selinux; +Cc: Richard Haines

When running 'make' from libselinux on Fedora 30 (gcc 9.1.1) the
following error is reported:

bute=const -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -Wstrict-overflow=5
-I../include -D_GNU_SOURCE  -DNO_ANDROID_BACKEND  -c -o booleans.o
booleans.c
booleans.c: In function ‘security_get_boolean_names’:
booleans.c:39:5: error: assuming signed overflow does not occur when
changing X +- C1 cmp C2 to X cmp C2 -+ C1 [-Werror=strict-overflow]
  39 | int security_get_boolean_names(char ***names, int *len)
      |    ^~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
make[1]: *** [Makefile:171: booleans.o] Error 1

This is caused by the '--i' in the: 'for (--i; i >= 0; --i)' loop.

Signed-off-by: Richard Haines <richard_c_haines@btinternet.com>
---
 libselinux/src/booleans.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/libselinux/src/booleans.c b/libselinux/src/booleans.c
index ab1e0754..882a5dca 100644
--- a/libselinux/src/booleans.c
+++ b/libselinux/src/booleans.c
@@ -81,8 +81,13 @@ int security_get_boolean_names(char ***names, int *len)
 	free(namelist);
 	return rc;
       bad_freen:
-	for (--i; i >= 0; --i)
+	if (i == 0)
+		goto bad_freen1;
+	else if (i > 0)
+		--i;
+	for (; i >= 0; --i)
 		free(n[i]);
+bad_freen1:
 	free(n);
       bad:
 	goto out;
-- 
2.21.0


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

* Re: [PATCH] libselinux: Fix security_get_boolean_names build error
  2019-07-03 14:12 [PATCH] libselinux: Fix security_get_boolean_names build error Richard Haines
@ 2019-07-07 21:02 ` Nicolas Iooss
  0 siblings, 0 replies; 4+ messages in thread
From: Nicolas Iooss @ 2019-07-07 21:02 UTC (permalink / raw)
  To: Richard Haines; +Cc: selinux

On Wed, Jul 3, 2019 at 5:22 PM Richard Haines
<richard_c_haines@btinternet.com> wrote:
>
> When running 'make' from libselinux on Fedora 30 (gcc 9.1.1) the
> following error is reported:
>
> bute=const -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -Wstrict-overflow=5
> -I../include -D_GNU_SOURCE  -DNO_ANDROID_BACKEND  -c -o booleans.o
> booleans.c
> booleans.c: In function ‘security_get_boolean_names’:
> booleans.c:39:5: error: assuming signed overflow does not occur when
> changing X +- C1 cmp C2 to X cmp C2 -+ C1 [-Werror=strict-overflow]
>   39 | int security_get_boolean_names(char ***names, int *len)
>       |    ^~~~~~~~~~~~~~~~~~~~~~~~~~
> cc1: all warnings being treated as errors
> make[1]: *** [Makefile:171: booleans.o] Error 1
>
> This is caused by the '--i' in the: 'for (--i; i >= 0; --i)' loop.
>
> Signed-off-by: Richard Haines <richard_c_haines@btinternet.com>
> ---
>  libselinux/src/booleans.c | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/libselinux/src/booleans.c b/libselinux/src/booleans.c
> index ab1e0754..882a5dca 100644
> --- a/libselinux/src/booleans.c
> +++ b/libselinux/src/booleans.c
> @@ -81,8 +81,13 @@ int security_get_boolean_names(char ***names, int *len)
>         free(namelist);
>         return rc;
>        bad_freen:
> -       for (--i; i >= 0; --i)
> +       if (i == 0)
> +               goto bad_freen1;
> +       else if (i > 0)
> +               --i;
> +       for (; i >= 0; --i)
>                 free(n[i]);
> +bad_freen1:
>         free(n);
>        bad:
>         goto out;
> --
> 2.21.0
>

Hi,
Thanks for your patch. It looks more complicated than it should be.
Why do you introduce a new label instead of a simpler if statement?
For example I think of this code (I have not tested it and it may
contain issues):

bad_freen:
    if (i > 0) {
        for (--i; i >= 0; --i)
            free(n[i]);
    }
    free(n);

>From my point of view, this would be easier to maintain. If you have a
good reason for using a new goto label, please add some sentences
about this in the patch description or/and in a comment next to the
modified lines.

Thanks,
Nicolas


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

* Re: [PATCH] libselinux: Fix security_get_boolean_names build error
  2019-07-02 18:21 Richard Haines
@ 2019-07-07 17:24 ` Richard Haines
  0 siblings, 0 replies; 4+ messages in thread
From: Richard Haines @ 2019-07-07 17:24 UTC (permalink / raw)
  To: selinux

On Tue, 2019-07-02 at 19:21 +0100, Richard Haines wrote:
> When running 'make' from libselinux on Fedora 30 (gcc 9.1.1) the
> following error is reported:
> 
> bute=const -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -Wstrict-overflow=5
> -I../include -D_GNU_SOURCE  -DNO_ANDROID_BACKEND  -c -o booleans.o
> booleans.c
> booleans.c: In function ‘security_get_boolean_names’:
> booleans.c:39:5: error: assuming signed overflow does not occur when
> changing X +- C1 cmp C2 to X cmp C2 -+ C1 [-Werror=strict-overflow]
>   39 | int security_get_boolean_names(char ***names, int *len)
>       |    ^~~~~~~~~~~~~~~~~~~~~~~~~~
> cc1: all warnings being treated as errors
> make[1]: *** [Makefile:171: booleans.o] Error 1
> 
> This is because of 'for (--i; i >= 0; --i)', however the --i is not
> required anyway as proven when simulating oom and running valgrind.

Please ignore this patch. Tried to cancel but delivered to list four
days later. The [1] patch is the correct one to review.

[1] 
https://lore.kernel.org/selinux/20190703141255.6321-1-richard_c_haines@btinternet.com/T/#u

> 
> Signed-off-by: Richard Haines <richard_c_haines@btinternet.com>
> ---
>  libselinux/src/booleans.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/libselinux/src/booleans.c b/libselinux/src/booleans.c
> index ab1e0754..33bf13c7 100644
> --- a/libselinux/src/booleans.c
> +++ b/libselinux/src/booleans.c
> @@ -81,7 +81,7 @@ int security_get_boolean_names(char ***names, int
> *len)
>  	free(namelist);
>  	return rc;
>        bad_freen:
> -	for (--i; i >= 0; --i)
> +	for (; i >= 0; --i)
>  		free(n[i]);
>  	free(n);
>        bad:


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

* [PATCH] libselinux: Fix security_get_boolean_names build error
@ 2019-07-02 18:21 Richard Haines
  2019-07-07 17:24 ` Richard Haines
  0 siblings, 1 reply; 4+ messages in thread
From: Richard Haines @ 2019-07-02 18:21 UTC (permalink / raw)
  To: selinux; +Cc: Richard Haines

When running 'make' from libselinux on Fedora 30 (gcc 9.1.1) the
following error is reported:

bute=const -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -Wstrict-overflow=5
-I../include -D_GNU_SOURCE  -DNO_ANDROID_BACKEND  -c -o booleans.o
booleans.c
booleans.c: In function ‘security_get_boolean_names’:
booleans.c:39:5: error: assuming signed overflow does not occur when
changing X +- C1 cmp C2 to X cmp C2 -+ C1 [-Werror=strict-overflow]
  39 | int security_get_boolean_names(char ***names, int *len)
      |    ^~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
make[1]: *** [Makefile:171: booleans.o] Error 1

This is because of 'for (--i; i >= 0; --i)', however the --i is not
required anyway as proven when simulating oom and running valgrind.

Signed-off-by: Richard Haines <richard_c_haines@btinternet.com>
---
 libselinux/src/booleans.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libselinux/src/booleans.c b/libselinux/src/booleans.c
index ab1e0754..33bf13c7 100644
--- a/libselinux/src/booleans.c
+++ b/libselinux/src/booleans.c
@@ -81,7 +81,7 @@ int security_get_boolean_names(char ***names, int *len)
 	free(namelist);
 	return rc;
       bad_freen:
-	for (--i; i >= 0; --i)
+	for (; i >= 0; --i)
 		free(n[i]);
 	free(n);
       bad:
-- 
2.21.0


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

end of thread, other threads:[~2019-07-07 21:03 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-03 14:12 [PATCH] libselinux: Fix security_get_boolean_names build error Richard Haines
2019-07-07 21:02 ` Nicolas Iooss
  -- strict thread matches above, loose matches on Subject: below --
2019-07-02 18:21 Richard Haines
2019-07-07 17:24 ` Richard Haines

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).