linux-nfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Malahal Naineni <malahal@us.ibm.com>
To: linux-nfs@vger.kernel.org
Subject: Re: [PATCH 1/2] nfs4-acl-tools: Fix segfault if format of the input file is incorrect
Date: Tue, 26 Jul 2011 10:58:38 -0700	[thread overview]
Message-ID: <20110726175838.GA13663@us.ibm.com> (raw)
In-Reply-To: <4E2E64AA.1090408@linux.vnet.ibm.com>

Venkateswararao Jujjuri [jvrao@linux.vnet.ibm.com] wrote:
> 
> On 07/21/2011 01:35 PM, Malahal Naineni wrote:
> >The sizeof operator, when applied to a parameter declared to have array,
> >yields the size of the adjusted (pointer) type, even if the parameter
> >declaration specifies a length.
> >
> >---
> >  libnfs4acl/nfs4_ace_from_string.c |    2 +-
> >  1 files changed, 1 insertions(+), 1 deletions(-)
> >
> >diff --git a/libnfs4acl/nfs4_ace_from_string.c b/libnfs4acl/nfs4_ace_from_string.c
> >index 9d877fb..462fcc0 100644
> >--- a/libnfs4acl/nfs4_ace_from_string.c
> >+++ b/libnfs4acl/nfs4_ace_from_string.c
> >@@ -100,7 +100,7 @@ parse_alloc_fields(char *buf, char *fields[NUMFIELDS])
> >  	if (!buf)
> >  		return -EINVAL;
> >
> >-	memset(fields, 0, sizeof(fields));
> >+	memset(fields, 0, sizeof(char *) * NUMFIELDS);
> >
> >  	for (i = 0; buf[i] != '\0'; i++) {
> >  		if (buf[i] == ':')
> 
> Could it be compiler specific? It is working fine for me
> 
> 
> Test]$ cat sizeof.c
> ===========
> #include <stdio.h>
> #define NUMFIELDS 10
> main()
> {
> 	char *fields1[NUMFIELDS];
> 	char fields2[NUMFIELDS];
> 
> 	printf("sizeof(fields1):%d sizeof(char *)*NUMFIELDS:%d\n",
> sizeof(fields1), sizeof(char *)*NUMFIELDS);
> 	printf("sizeof(fields2):%d sizeof(char)*NUMFIELDS:%d\n",
> sizeof(fields2), sizeof(char)*NUMFIELDS);
> }

It works as expected in the definition scope. It doesn't work "when
applied to a parameter declared to have array". It looks like, this is
part of the C99 spec, so can't be compiler specific. Try this:

static void fun(char *a[10])
{
 	printf("sizeof returned: %d\n", sizeof(a));
}

  reply	other threads:[~2011-07-26 17:58 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-07-21 20:35 [PATCH 1/2] nfs4-acl-tools: Fix segfault if format of the input file is incorrect Malahal Naineni
2011-07-21 20:35 ` [PATCH 2/2] nfs4-acl-tools: Don't call free_fields when memory isn't allocated Malahal Naineni
2011-07-26  6:54 ` [PATCH 1/2] nfs4-acl-tools: Fix segfault if format of the input file is incorrect Venkateswararao Jujjuri
2011-07-26 17:58   ` Malahal Naineni [this message]
2011-08-05 20:05     ` J. Bruce Fields
2011-08-05 20:50       ` Malahal Naineni

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=20110726175838.GA13663@us.ibm.com \
    --to=malahal@us.ibm.com \
    --cc=linux-nfs@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).