selinux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: jwcart2 <jwcart2@tycho.nsa.gov>
To: Nicolas Iooss <nicolas.iooss@m4x.org>, selinux@vger.kernel.org
Subject: Re: [Non-DoD Source] [PATCH 1/1] libsepol: do not use uninitialized value for low_value
Date: Mon, 4 Feb 2019 11:54:09 -0500	[thread overview]
Message-ID: <0e0c3fc1-e6db-d59f-5f8c-5cc1b58705d1@tycho.nsa.gov> (raw)
In-Reply-To: <20190203110152.15064-1-nicolas.iooss@m4x.org>

On 2/3/19 6:01 AM, Nicolas Iooss wrote:
> clang's static analyzer reports a warning when low_bit is used without
> having been initialized in statements such as:
> 
>      low_value = low_bit << 8;
> 
> The warning is: "Result of operation is garbage or undefined".
> 
> This is caused by low_bit being only initialized when in_range is true.
> This issue is not critical because low_value is only used in an
> "if (in_range)" block. Silence this warning by moving low_value's
> assignment inside this block.
> 
> Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>

Acked-by: James Carter <jwcart2@tycho.nsa.gov>

> ---
>   libsepol/src/kernel_to_cil.c | 4 ++--
>   libsepol/src/module_to_cil.c | 4 ++--
>   libsepol/src/util.c          | 4 ++--
>   3 files changed, 6 insertions(+), 6 deletions(-)
> 
> diff --git a/libsepol/src/kernel_to_cil.c b/libsepol/src/kernel_to_cil.c
> index 63e4d4899758..cd3554e8dfd9 100644
> --- a/libsepol/src/kernel_to_cil.c
> +++ b/libsepol/src/kernel_to_cil.c
> @@ -1614,8 +1614,8 @@ static char *xperms_to_str(avtab_extended_perms_t *xperms)
>   
>   		if (xperms->specified & AVTAB_XPERMS_IOCTLFUNCTION) {
>   			value = xperms->driver<<8 | bit;
> -			low_value = xperms->driver<<8 | low_bit;
>   			if (in_range) {
> +				low_value = xperms->driver<<8 | low_bit;
>   				len = snprintf(p, remaining, " (range 0x%hx 0x%hx)", low_value, value);
>   				in_range = 0;
>   			} else {
> @@ -1623,8 +1623,8 @@ static char *xperms_to_str(avtab_extended_perms_t *xperms)
>   			}
>   		} else if (xperms->specified & AVTAB_XPERMS_IOCTLDRIVER) {
>   			value = bit << 8;
> -			low_value = low_bit << 8;
>   			if (in_range) {
> +				low_value = low_bit << 8;
>   				len = snprintf(p, remaining, " (range 0x%hx 0x%hx)", low_value, (uint16_t) (value|0xff));
>   				in_range = 0;
>   			} else {
> diff --git a/libsepol/src/module_to_cil.c b/libsepol/src/module_to_cil.c
> index 4cb44e0ee657..f04589edaeff 100644
> --- a/libsepol/src/module_to_cil.c
> +++ b/libsepol/src/module_to_cil.c
> @@ -655,8 +655,8 @@ static int xperms_to_cil(const av_extended_perms_t *xperms)
>   
>   		if (xperms->specified & AVTAB_XPERMS_IOCTLFUNCTION) {
>   			value = xperms->driver<<8 | bit;
> -			low_value = xperms->driver<<8 | low_bit;
>   			if (in_range) {
> +				low_value = xperms->driver<<8 | low_bit;
>   				cil_printf("(range 0x%hx 0x%hx)", low_value, value);
>   				in_range = 0;
>   			} else {
> @@ -664,8 +664,8 @@ static int xperms_to_cil(const av_extended_perms_t *xperms)
>   			}
>   		} else if (xperms->specified & AVTAB_XPERMS_IOCTLDRIVER) {
>   			value = bit << 8;
> -			low_value = low_bit << 8;
>   			if (in_range) {
> +				low_value = low_bit << 8;
>   				cil_printf("(range 0x%hx 0x%hx)", low_value, (uint16_t) (value|0xff));
>   				in_range = 0;
>   			} else {
> diff --git a/libsepol/src/util.c b/libsepol/src/util.c
> index b00251c69aa5..a4008882b94b 100644
> --- a/libsepol/src/util.c
> +++ b/libsepol/src/util.c
> @@ -159,16 +159,16 @@ char *sepol_extended_perms_to_string(avtab_extended_perms_t *xperms)
>   
>   		if (xperms->specified & AVTAB_XPERMS_IOCTLFUNCTION) {
>   			value = xperms->driver<<8 | bit;
> -			low_value = xperms->driver<<8 | low_bit;
>   			if (in_range) {
> +				low_value = xperms->driver<<8 | low_bit;
>   				len = snprintf(p, sizeof(xpermsbuf) - xpermslen, "0x%hx-0x%hx ", low_value, value);
>   			} else {
>   				len = snprintf(p, sizeof(xpermsbuf) - xpermslen, "0x%hx ", value);
>   			}
>   		} else if (xperms->specified & AVTAB_XPERMS_IOCTLDRIVER) {
>   			value = bit << 8;
> -			low_value = low_bit << 8;
>   			if (in_range) {
> +				low_value = low_bit << 8;
>   				len = snprintf(p, sizeof(xpermsbuf) - xpermslen, "0x%hx-0x%hx ", low_value, (uint16_t) (value|0xff));
>   			} else {
>   				len = snprintf(p, sizeof(xpermsbuf) - xpermslen, "0x%hx-0x%hx ", value, (uint16_t) (value|0xff));
> 


-- 
James Carter <jwcart2@tycho.nsa.gov>
National Security Agency

  reply	other threads:[~2019-02-04 16:54 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-03 11:01 [PATCH 1/1] libsepol: do not use uninitialized value for low_value Nicolas Iooss
2019-02-04 16:54 ` jwcart2 [this message]
2019-02-06  8:12   ` [Non-DoD Source] " Petr Lautrbach

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=0e0c3fc1-e6db-d59f-5f8c-5cc1b58705d1@tycho.nsa.gov \
    --to=jwcart2@tycho.nsa.gov \
    --cc=nicolas.iooss@m4x.org \
    --cc=selinux@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).