2007-05-27 10:34:52

by Jeff Garzik

[permalink] [raw]
Subject: [PATCH] NFSD: fix uninitialized variable


Unlike many of the bogus warnings spewed by gcc, this one actually
complains about a real bug:

fs/nfsd/nfs4acl.c: In function ‘_posix_to_nfsv4_one’:
fs/nfsd/nfs4acl.c:227: warning: ‘pas.owner’ may be used uninitialized in this function
fs/nfsd/nfs4acl.c:227: warning: ‘pas.group’ may be used uninitialized in this function
fs/nfsd/nfs4acl.c:227: warning: ‘pas.other’ may be used uninitialized in this function

Signed-off-by: Jeff Garzik <[email protected]>

diff --git a/fs/nfsd/nfs4acl.c b/fs/nfsd/nfs4acl.c
index cc3b7ba..7fd4d44 100644
--- a/fs/nfsd/nfs4acl.c
+++ b/fs/nfsd/nfs4acl.c
@@ -183,8 +183,8 @@ static void
summarize_posix_acl(struct posix_acl *acl, struct posix_acl_summary *pas)
{
struct posix_acl_entry *pa, *pe;
- pas->users = 0;
- pas->groups = 0;
+
+ memset(pas, 0, sizeof(*pas));
pas->mask = 07;

pe = acl->a_entries + acl->a_count;


2007-05-29 03:01:14

by J. Bruce Fields

[permalink] [raw]
Subject: Re: [NFS] [PATCH] NFSD: fix uninitialized variable

On Sun, May 27, 2007 at 06:34:42AM -0400, Jeff Garzik wrote:
>
> Unlike many of the bogus warnings spewed by gcc, this one actually
> complains about a real bug:

No, the calls to posix_acl_valid() in nfs4_acl_posix_to_nfsv4() ensure
that the passed-in acl has ACL_USER_OBJ, ACL_GROUP_OBJ, and ACL_OTHER
entries, and hence that these fields will always be initialized.

But I don't want anyone else wasting their time on this. Should we cave
in and add the initialization here just to shut up gcc? Or would a
comment here help?

--b.

2007-05-29 03:19:36

by Jeff Garzik

[permalink] [raw]
Subject: Re: [NFS] [PATCH] NFSD: fix uninitialized variable

J. Bruce Fields wrote:
> On Sun, May 27, 2007 at 06:34:42AM -0400, Jeff Garzik wrote:
>> Unlike many of the bogus warnings spewed by gcc, this one actually
>> complains about a real bug:
>
> No, the calls to posix_acl_valid() in nfs4_acl_posix_to_nfsv4() ensure
> that the passed-in acl has ACL_USER_OBJ, ACL_GROUP_OBJ, and ACL_OTHER
> entries, and hence that these fields will always be initialized.

OK


> But I don't want anyone else wasting their time on this. Should we cave
> in and add the initialization here just to shut up gcc? Or would a
> comment here help?

Given what you said above, I don't see gcc, on its best day, will ever
know enough to validate that that variable is indeed always initialized.
So I would vote for silencing it on those grounds.

Jeff


2007-05-29 04:31:21

by Dave Young

[permalink] [raw]
Subject: Re: [NFS] [PATCH] NFSD: fix uninitialized variable

Hi,

> Given what you said above, I don't see gcc, on its best day, will ever
> know enough to validate that that variable is indeed always initialized.
> So I would vote for silencing it on those grounds.

I agree too. How about this one:

diff -dur linux/fs/nfsd/nfs4acl.c linux.new/fs/nfsd/nfs4acl.c
--- linux/fs/nfsd/nfs4acl.c 2007-05-29 12:28:29.000000000 +0000
+++ linux.new/fs/nfsd/nfs4acl.c 2007-05-29 12:30:45.000000000 +0000
@@ -183,8 +183,6 @@
summarize_posix_acl(struct posix_acl *acl, struct posix_acl_summary *pas)
{
struct posix_acl_entry *pa, *pe;
- pas->users = 0;
- pas->groups = 0;
pas->mask = 07;

pe = acl->a_entries + acl->a_count;
@@ -229,6 +227,7 @@
int eflag = ((flags & NFS4_ACL_TYPE_DEFAULT) ?
NFS4_INHERITANCE_FLAGS | NFS4_ACE_INHERIT_ONLY_ACE : 0);

+ memset(pas, 0, sizeof(struct posix_acl_summary);
BUG_ON(pacl->a_count < 3);
summarize_posix_acl(pacl, &pas);

Regards
dave

2007-05-29 07:29:35

by Matt Keenan

[permalink] [raw]
Subject: Re: [NFS] [PATCH] NFSD: fix uninitialized variable

young dave wrote:
> Hi,
>
>> Given what you said above, I don't see gcc, on its best day, will ever
>> know enough to validate that that variable is indeed always initialized.
>> So I would vote for silencing it on those grounds.
>
> I agree too. How about this one:
>
> diff -dur linux/fs/nfsd/nfs4acl.c linux.new/fs/nfsd/nfs4acl.c
> --- linux/fs/nfsd/nfs4acl.c 2007-05-29 12:28:29.000000000 +0000
> +++ linux.new/fs/nfsd/nfs4acl.c 2007-05-29 12:30:45.000000000 +0000
> @@ -183,8 +183,6 @@
> summarize_posix_acl(struct posix_acl *acl, struct posix_acl_summary *pas)
> {
> struct posix_acl_entry *pa, *pe;
> - pas->users = 0;
> - pas->groups = 0;
> pas->mask = 07;
>
> pe = acl->a_entries + acl->a_count;
> @@ -229,6 +227,7 @@
> int eflag = ((flags & NFS4_ACL_TYPE_DEFAULT) ?
> NFS4_INHERITANCE_FLAGS | NFS4_ACE_INHERIT_ONLY_ACE : 0);
>
> + memset(pas, 0, sizeof(struct posix_acl_summary);
> BUG_ON(pacl->a_count < 3);
> summarize_posix_acl(pacl, &pas);
>

^^^^^

apart from the fact that this patch won't compile let alone run...


Matt

2007-05-29 08:32:52

by Dave Young

[permalink] [raw]
Subject: Re: [NFS] [PATCH] NFSD: fix uninitialized variable

Hi, matt
embarrassed :)
below resend it.

diff -dur linux/fs/nfsd/nfs4acl.c linux.new/fs/nfsd/nfs4acl.c
--- linux/fs/nfsd/nfs4acl.c 2007-05-29 12:28:29.000000000 +0000
+++ linux.new/fs/nfsd/nfs4acl.c 2007-05-29 16:32:26.000000000 +0000
@@ -183,8 +183,6 @@
summarize_posix_acl(struct posix_acl *acl, struct posix_acl_summary *pas)
{
struct posix_acl_entry *pa, *pe;
- pas->users = 0;
- pas->groups = 0;
pas->mask = 07;

pe = acl->a_entries + acl->a_count;
@@ -229,6 +227,7 @@
int eflag = ((flags & NFS4_ACL_TYPE_DEFAULT) ?
NFS4_INHERITANCE_FLAGS | NFS4_ACE_INHERIT_ONLY_ACE : 0);

+ memset(pas, 0, sizeof(struct posix_acl_summary));
BUG_ON(pacl->a_count < 3);
summarize_posix_acl(pacl, &pas);

2007-05-29 19:52:42

by J. Bruce Fields

[permalink] [raw]
Subject: Re: [NFS] [PATCH] NFSD: fix uninitialized variable

On Mon, May 28, 2007 at 11:19:21PM -0400, Jeff Garzik wrote:
> J. Bruce Fields wrote:
> >But I don't want anyone else wasting their time on this. Should we cave
> >in and add the initialization here just to shut up gcc? Or would a
> >comment here help?
>
> Given what you said above, I don't see gcc, on its best day, will ever
> know enough to validate that that variable is indeed always initialized.

I recall there being arguments before about when to add initializations.
Unfortunately I can't remember the content of those arguments. But I
thought that on the gcc-haters side the complaint was exactly that gcc
was emitting warnings in cases where it could never hope to determine
whether an initialization is required. Am I misremembering?

> So I would vote for silencing it on those grounds.

That said, I'm OK with the extra initialization. Might be worth a
comment, though, just to avoid giving the wrong impression about the
assumptions here; something like:

--b.

diff --git a/fs/nfsd/nfs4acl.c b/fs/nfsd/nfs4acl.c
index cc3b7ba..4adb5ee 100644
--- a/fs/nfsd/nfs4acl.c
+++ b/fs/nfsd/nfs4acl.c
@@ -183,8 +183,13 @@ static void
summarize_posix_acl(struct posix_acl *acl, struct posix_acl_summary *pas)
{
struct posix_acl_entry *pa, *pe;
- pas->users = 0;
- pas->groups = 0;
+
+ /*
+ * Only pas.users and pas.groups need initialization; previous
+ * posix_acl_valid() calls ensure that the other fields will be
+ * initialized in the following loop. But, just to placate gcc:
+ */
+ memset(pas, 0, sizeof(*pas));
pas->mask = 07;

pe = acl->a_entries + acl->a_count;