xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] xen/xsm: Shut up GCC 5.1.1 warnings.
@ 2015-09-16 13:45 Konrad Rzeszutek Wilk
  2015-09-16 15:14 ` Julien Grall
  0 siblings, 1 reply; 5+ messages in thread
From: Konrad Rzeszutek Wilk @ 2015-09-16 13:45 UTC (permalink / raw)
  To: dgdegra, xen-devel; +Cc: Konrad Rzeszutek Wilk

policydb.c: In function ‘user_read’:
policydb.c:1443:26: error: ‘buf[2]’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
         usrdatum->bounds = le32_to_cpu(buf[2]);
                          ^
cc1: all warnings being treated as errors

Which makes no sense, as :
 1). A couple of lines above it is being filled (buf[2]).
 2). There are other instances of this which are not triggering this
     failure.

But GCC insists, and this patch stops the failures.

Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
---
 xen/xsm/flask/ss/policydb.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/xen/xsm/flask/ss/policydb.c b/xen/xsm/flask/ss/policydb.c
index a1060b1..cee259c 100644
--- a/xen/xsm/flask/ss/policydb.c
+++ b/xen/xsm/flask/ss/policydb.c
@@ -1274,6 +1274,7 @@ static int role_read(struct policydb *p, struct hashtab *h, void *fp)
     if ( rc < 0 )
         goto bad;
 
+    buf[2] = 0; /* To shut up compiler warnings. */
     len = le32_to_cpu(buf[0]);
     role->value = le32_to_cpu(buf[1]);
     if ( p->policyvers >= POLICYDB_VERSION_BOUNDARY )
@@ -1437,6 +1438,7 @@ static int user_read(struct policydb *p, struct hashtab *h, void *fp)
     if ( rc < 0 )
         goto bad;
 
+    buf[2] = 0; /* To shut up compiler warnings. */
     len = le32_to_cpu(buf[0]);
     usrdatum->value = le32_to_cpu(buf[1]);
     if ( p->policyvers >= POLICYDB_VERSION_BOUNDARY )
-- 
2.4.3


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

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

* Re: [PATCH] xen/xsm: Shut up GCC 5.1.1 warnings.
  2015-09-16 13:45 [PATCH] xen/xsm: Shut up GCC 5.1.1 warnings Konrad Rzeszutek Wilk
@ 2015-09-16 15:14 ` Julien Grall
  2015-09-16 16:18   ` Konrad Rzeszutek Wilk
  0 siblings, 1 reply; 5+ messages in thread
From: Julien Grall @ 2015-09-16 15:14 UTC (permalink / raw)
  To: Konrad Rzeszutek Wilk, dgdegra, xen-devel

Hi Konrad,

On 16/09/15 14:45, Konrad Rzeszutek Wilk wrote:
> policydb.c: In function ‘user_read’:
> policydb.c:1443:26: error: ‘buf[2]’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
>          usrdatum->bounds = le32_to_cpu(buf[2]);
>                           ^
> cc1: all warnings being treated as errors
> 
> Which makes no sense, as :
>  1). A couple of lines above it is being filled (buf[2]).

Not in every case, if p->policyvers < POLICYDB_VERSION_BOUNDARY, buf[2]
won't be initialized.

>  2). There are other instances of this which are not triggering this
>      failure.
> But GCC insists, and this patch stops the failures.
> 
> Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
> ---
>  xen/xsm/flask/ss/policydb.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/xen/xsm/flask/ss/policydb.c b/xen/xsm/flask/ss/policydb.c
> index a1060b1..cee259c 100644
> --- a/xen/xsm/flask/ss/policydb.c
> +++ b/xen/xsm/flask/ss/policydb.c
> @@ -1274,6 +1274,7 @@ static int role_read(struct policydb *p, struct hashtab *h, void *fp)
>      if ( rc < 0 )
>          goto bad;
>  
> +    buf[2] = 0; /* To shut up compiler warnings. */

By doing this, you will override buf[2] when the policy version >=
POLICYDB_VERSION_BOUNDARY.

>      len = le32_to_cpu(buf[0]);
>      role->value = le32_to_cpu(buf[1]);
>      if ( p->policyvers >= POLICYDB_VERSION_BOUNDARY )
> @@ -1437,6 +1438,7 @@ static int user_read(struct policydb *p, struct hashtab *h, void *fp)
>      if ( rc < 0 )
>          goto bad;
>  
> +    buf[2] = 0; /* To shut up compiler warnings. */

Ditto.

>      len = le32_to_cpu(buf[0]);
>      usrdatum->value = le32_to_cpu(buf[1]);
>      if ( p->policyvers >= POLICYDB_VERSION_BOUNDARY )
> 

Regards,

-- 
Julien Grall

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

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

* Re: [PATCH] xen/xsm: Shut up GCC 5.1.1 warnings.
  2015-09-16 15:14 ` Julien Grall
@ 2015-09-16 16:18   ` Konrad Rzeszutek Wilk
  0 siblings, 0 replies; 5+ messages in thread
From: Konrad Rzeszutek Wilk @ 2015-09-16 16:18 UTC (permalink / raw)
  To: Julien Grall; +Cc: xen-devel, dgdegra

On Wed, Sep 16, 2015 at 04:14:27PM +0100, Julien Grall wrote:
> Hi Konrad,
> 
> On 16/09/15 14:45, Konrad Rzeszutek Wilk wrote:
> > policydb.c: In function ‘user_read’:
> > policydb.c:1443:26: error: ‘buf[2]’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
> >          usrdatum->bounds = le32_to_cpu(buf[2]);
> >                           ^
> > cc1: all warnings being treated as errors
> > 
> > Which makes no sense, as :
> >  1). A couple of lines above it is being filled (buf[2]).
> 
> Not in every case, if p->policyvers < POLICYDB_VERSION_BOUNDARY, buf[2]
> won't be initialized.
> 
> >  2). There are other instances of this which are not triggering this
> >      failure.
> > But GCC insists, and this patch stops the failures.
> > 
> > Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
> > ---
> >  xen/xsm/flask/ss/policydb.c | 2 ++
> >  1 file changed, 2 insertions(+)
> > 
> > diff --git a/xen/xsm/flask/ss/policydb.c b/xen/xsm/flask/ss/policydb.c
> > index a1060b1..cee259c 100644
> > --- a/xen/xsm/flask/ss/policydb.c
> > +++ b/xen/xsm/flask/ss/policydb.c
> > @@ -1274,6 +1274,7 @@ static int role_read(struct policydb *p, struct hashtab *h, void *fp)
> >      if ( rc < 0 )
> >          goto bad;
> >  
> > +    buf[2] = 0; /* To shut up compiler warnings. */
> 
> By doing this, you will override buf[2] when the policy version >=
> POLICYDB_VERSION_BOUNDARY.
> 
> >      len = le32_to_cpu(buf[0]);
> >      role->value = le32_to_cpu(buf[1]);
> >      if ( p->policyvers >= POLICYDB_VERSION_BOUNDARY )
> > @@ -1437,6 +1438,7 @@ static int user_read(struct policydb *p, struct hashtab *h, void *fp)
> >      if ( rc < 0 )
> >          goto bad;
> >  
> > +    buf[2] = 0; /* To shut up compiler warnings. */
> 
> Ditto.

Duh! I had it in a differente location in the earlier patch and
then moved down to make it after the 'goto bad'.

Thanks!
> 
> >      len = le32_to_cpu(buf[0]);
> >      usrdatum->value = le32_to_cpu(buf[1]);
> >      if ( p->policyvers >= POLICYDB_VERSION_BOUNDARY )
> > 
> 
> Regards,
> 
> -- 
> Julien Grall

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

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

* [PATCH] xen/xsm: Shut up GCC 5.1.1 warnings.
@ 2015-09-16 17:12 Konrad Rzeszutek Wilk
  2015-09-16 19:05 ` Andrew Cooper
  0 siblings, 1 reply; 5+ messages in thread
From: Konrad Rzeszutek Wilk @ 2015-09-16 17:12 UTC (permalink / raw)
  To: dgdegra, xen-devel; +Cc: Konrad Rzeszutek Wilk

policydb.c: In function ‘user_read’:
policydb.c:1443:26: error: ‘buf[2]’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
         usrdatum->bounds = le32_to_cpu(buf[2]);
                          ^
cc1: all warnings being treated as errors

Which makes no sense, as :
 1). A couple of lines above it is being filled (buf[2]).
 2). There are other instances of this which are not triggering this
     failure.

But GCC insists, and this patch stops the failures.

Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
---
v2: Wrong placement of the buf[2]=0;
---
 xen/xsm/flask/ss/policydb.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/xen/xsm/flask/ss/policydb.c b/xen/xsm/flask/ss/policydb.c
index a1060b1..30ef9c5 100644
--- a/xen/xsm/flask/ss/policydb.c
+++ b/xen/xsm/flask/ss/policydb.c
@@ -1266,6 +1266,7 @@ static int role_read(struct policydb *p, struct hashtab *h, void *fp)
         goto out;
     }
 
+    buf[2] = 0; /* To shut up compiler warnings. */
     if ( p->policyvers >= POLICYDB_VERSION_BOUNDARY )
         rc = next_entry(buf, fp, sizeof(buf[0]) * 3);
     else
@@ -1429,6 +1430,7 @@ static int user_read(struct policydb *p, struct hashtab *h, void *fp)
         goto out;
     }
 
+    buf[2] = 0; /* To shut up compiler warnings. */
     if ( p->policyvers >= POLICYDB_VERSION_BOUNDARY )
         rc = next_entry(buf, fp, sizeof(buf[0]) * 3);
     else
-- 
2.4.3


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

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

* Re: [PATCH] xen/xsm: Shut up GCC 5.1.1 warnings.
  2015-09-16 17:12 Konrad Rzeszutek Wilk
@ 2015-09-16 19:05 ` Andrew Cooper
  0 siblings, 0 replies; 5+ messages in thread
From: Andrew Cooper @ 2015-09-16 19:05 UTC (permalink / raw)
  To: Konrad Rzeszutek Wilk, dgdegra, xen-devel

On 16/09/2015 18:12, Konrad Rzeszutek Wilk wrote:
> policydb.c: In function ‘user_read’:
> policydb.c:1443:26: error: ‘buf[2]’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
>          usrdatum->bounds = le32_to_cpu(buf[2]);
>                           ^
> cc1: all warnings being treated as errors
>
> Which makes no sense, as :
>  1). A couple of lines above it is being filled (buf[2]).
>  2). There are other instances of this which are not triggering this
>      failure.
>
> But GCC insists, and this patch stops the failures.
>
> Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>

A better bet would just be to initialise buf at declaration time, so
"__le32 buf[3] = { 0 };"

The reason this warning is firing is that C may not assume that
p->policyvers doesn't change between the next_entry() call and the
role->bounds assignment.  Pulling p->policyvers into a local variable
might also be sufficient.

~Andrew

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

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

end of thread, other threads:[~2015-09-16 19:05 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-09-16 13:45 [PATCH] xen/xsm: Shut up GCC 5.1.1 warnings Konrad Rzeszutek Wilk
2015-09-16 15:14 ` Julien Grall
2015-09-16 16:18   ` Konrad Rzeszutek Wilk
  -- strict thread matches above, loose matches on Subject: below --
2015-09-16 17:12 Konrad Rzeszutek Wilk
2015-09-16 19:05 ` Andrew Cooper

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).