All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] libnfsidmap: id_as_chars() fails zero value ids.
@ 2014-04-30 15:18 Steve Dickson
  2014-04-30 16:30 ` Jeff Layton
  0 siblings, 1 reply; 3+ messages in thread
From: Steve Dickson @ 2014-04-30 15:18 UTC (permalink / raw)
  To: Linux NFS Mailing list

Root has a zero value id which is valid and
should not be mapped to nfsnobody

Signed-off-by: Steve Dickson <steved@redhat.com>
---
 libnfsidmap.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/libnfsidmap.c b/libnfsidmap.c
index 641d766..92bc493 100644
--- a/libnfsidmap.c
+++ b/libnfsidmap.c
@@ -99,8 +99,12 @@ static char * toupper_str(char *s)
 static int id_as_chars(char *name, int *id)
 {
 	long int value = strtol(name, NULL, 10);
-	if (value == 0)
-		return 0;
+
+	if (value == 0) {
+		/* zero value ids are valid */
+		if (strcmp(name, "0") != 0)
+			return 0;
+	}
 	*id = (int)value;
 	return 1;
 }
-- 
1.9.0


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

* Re: [PATCH] libnfsidmap: id_as_chars() fails zero value ids.
  2014-04-30 15:18 [PATCH] libnfsidmap: id_as_chars() fails zero value ids Steve Dickson
@ 2014-04-30 16:30 ` Jeff Layton
  2014-04-30 17:31   ` Steve Dickson
  0 siblings, 1 reply; 3+ messages in thread
From: Jeff Layton @ 2014-04-30 16:30 UTC (permalink / raw)
  To: Steve Dickson; +Cc: Linux NFS Mailing list

On Wed, 30 Apr 2014 11:18:28 -0400
Steve Dickson <steved@redhat.com> wrote:

> Root has a zero value id which is valid and
> should not be mapped to nfsnobody
> 
> Signed-off-by: Steve Dickson <steved@redhat.com>
> ---
>  libnfsidmap.c | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/libnfsidmap.c b/libnfsidmap.c
> index 641d766..92bc493 100644
> --- a/libnfsidmap.c
> +++ b/libnfsidmap.c
> @@ -99,8 +99,12 @@ static char * toupper_str(char *s)
>  static int id_as_chars(char *name, int *id)
>  {
>  	long int value = strtol(name, NULL, 10);
> -	if (value == 0)
> -		return 0;
> +
> +	if (value == 0) {
> +		/* zero value ids are valid */
> +		if (strcmp(name, "0") != 0)
> +			return 0;
> +	}
>  	*id = (int)value;
>  	return 1;
>  }

Well spotted. I think though that instead of doing the strcmp, you
should instead just use the endptr value in the strtol call to determine
whether the string was completely converted. If it isn't, we can just
return 0 here. If it is completely converted then you know that you got
a legit "0" string.

-- 
Jeff Layton <jlayton@poochiereds.net>

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

* Re: [PATCH] libnfsidmap: id_as_chars() fails zero value ids.
  2014-04-30 16:30 ` Jeff Layton
@ 2014-04-30 17:31   ` Steve Dickson
  0 siblings, 0 replies; 3+ messages in thread
From: Steve Dickson @ 2014-04-30 17:31 UTC (permalink / raw)
  To: Jeff Layton; +Cc: Linux NFS Mailing list



On 04/30/2014 12:30 PM, Jeff Layton wrote:
> On Wed, 30 Apr 2014 11:18:28 -0400
> Steve Dickson <steved@redhat.com> wrote:
> 
>> Root has a zero value id which is valid and
>> should not be mapped to nfsnobody
>>
>> Signed-off-by: Steve Dickson <steved@redhat.com>
>> ---
>>  libnfsidmap.c | 8 ++++++--
>>  1 file changed, 6 insertions(+), 2 deletions(-)
>>
>> diff --git a/libnfsidmap.c b/libnfsidmap.c
>> index 641d766..92bc493 100644
>> --- a/libnfsidmap.c
>> +++ b/libnfsidmap.c
>> @@ -99,8 +99,12 @@ static char * toupper_str(char *s)
>>  static int id_as_chars(char *name, int *id)
>>  {
>>  	long int value = strtol(name, NULL, 10);
>> -	if (value == 0)
>> -		return 0;
>> +
>> +	if (value == 0) {
>> +		/* zero value ids are valid */
>> +		if (strcmp(name, "0") != 0)
>> +			return 0;
>> +	}
>>  	*id = (int)value;
>>  	return 1;
>>  }
> 
> Well spotted. I think though that instead of doing the strcmp, you
> should instead just use the endptr value in the strtol call to determine
> whether the string was completely converted. If it isn't, we can just
> return 0 here. If it is completely converted then you know that you got
> a legit "0" string.
> 
Yeah that wold have been a good idea but I've already
committed and pushed this version... ;-)

I'm thinking it's six of one and a half a dozen of another
both version will do the same thing... but if it bothersome, 
send me a patch....

steved.

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

end of thread, other threads:[~2014-04-30 17:31 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-04-30 15:18 [PATCH] libnfsidmap: id_as_chars() fails zero value ids Steve Dickson
2014-04-30 16:30 ` Jeff Layton
2014-04-30 17:31   ` Steve Dickson

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.