2015-12-02 11:17:36

by Vivek Trivedi

[permalink] [raw]
Subject: [PATCH 1/2] nfs-utils: libnsm.a: do not close file if open failed

If file open failed, no need to issue close system call in
nsm_get_state and closeall.

Signed-off-by: Vivek Trivedi <[email protected]>
---
support/nfs/closeall.c | 3 ++-
support/nsm/file.c | 3 ++-
2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/support/nfs/closeall.c b/support/nfs/closeall.c
index 38fb162..a69bf35 100644
--- a/support/nfs/closeall.c
+++ b/support/nfs/closeall.c
@@ -31,6 +31,7 @@ closeall(int min)
} else {
int fd = sysconf(_SC_OPEN_MAX);
while (--fd >= min)
- (void) close(fd);
+ if(fd >= 0)
+ (void) close(fd);
}
}
diff --git a/support/nsm/file.c b/support/nsm/file.c
index 4711c2c..7a8b504 100644
--- a/support/nsm/file.c
+++ b/support/nsm/file.c
@@ -536,7 +536,8 @@ nsm_get_state(_Bool update)
state++;

update:
- (void)close(fd);
+ if(fd >= 0)
+ (void)close(fd);

if (update) {
state += 2;
--
1.7.9.5



2015-12-02 11:18:33

by Vivek Trivedi

[permalink] [raw]
Subject: [PATCH 2/2] nfs-utils: mount.nfs: fix null pointer derefernce in nfs_parse_simple_hostname

In function nfs_parse_simple_hostname, hostname can be NULL,
dereferncing it while passing it to free(*hostname) may result in segfault.

Signed-off-by: Vivek Trivedi <[email protected]>
---
utils/mount/parse_dev.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/utils/mount/parse_dev.c b/utils/mount/parse_dev.c
index d64b83d..0d3bcb9 100644
--- a/utils/mount/parse_dev.c
+++ b/utils/mount/parse_dev.c
@@ -118,7 +118,8 @@ static int nfs_parse_simple_hostname(const char *dev,
if (pathname) {
*pathname = strndup(colon, path_len);
if (*pathname == NULL) {
- free(*hostname);
+ if (hostname)
+ free(*hostname);
return nfs_pdn_nomem_err();
}
}
--
1.7.9.5


2015-12-02 16:11:11

by Steve Dickson

[permalink] [raw]
Subject: Re: [PATCH 1/2] nfs-utils: libnsm.a: do not close file if open failed



On 12/02/2015 06:16 AM, Vivek Trivedi wrote:
> If file open failed, no need to issue close system call in
> nsm_get_state and closeall.
I guess this makes sense... but what problem is this patch fixing?

steved.

>
> Signed-off-by: Vivek Trivedi <[email protected]>
> ---
> support/nfs/closeall.c | 3 ++-
> support/nsm/file.c | 3 ++-
> 2 files changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/support/nfs/closeall.c b/support/nfs/closeall.c
> index 38fb162..a69bf35 100644
> --- a/support/nfs/closeall.c
> +++ b/support/nfs/closeall.c
> @@ -31,6 +31,7 @@ closeall(int min)
> } else {
> int fd = sysconf(_SC_OPEN_MAX);
> while (--fd >= min)
> - (void) close(fd);
> + if(fd >= 0)
> + (void) close(fd);
> }
> }
> diff --git a/support/nsm/file.c b/support/nsm/file.c
> index 4711c2c..7a8b504 100644
> --- a/support/nsm/file.c
> +++ b/support/nsm/file.c
> @@ -536,7 +536,8 @@ nsm_get_state(_Bool update)
> state++;
>
> update:
> - (void)close(fd);
> + if(fd >= 0)
> + (void)close(fd);
>
> if (update) {
> state += 2;
>

2015-12-02 16:16:21

by Steve Dickson

[permalink] [raw]
Subject: Re: [PATCH 2/2] nfs-utils: mount.nfs: fix null pointer derefernce in nfs_parse_simple_hostname

hello,

On 12/02/2015 06:16 AM, Vivek Trivedi wrote:
> In function nfs_parse_simple_hostname, hostname can be NULL,
> dereferncing it while passing it to free(*hostname) may result in segfault.
Again I can see the logic but I wondering why/how a NULL hostname
is being passed. I don't see how a NULL hostname can be passed
in esp during a mount....

steved.

>
> Signed-off-by: Vivek Trivedi <[email protected]>
> ---
> utils/mount/parse_dev.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/utils/mount/parse_dev.c b/utils/mount/parse_dev.c
> index d64b83d..0d3bcb9 100644
> --- a/utils/mount/parse_dev.c
> +++ b/utils/mount/parse_dev.c
> @@ -118,7 +118,8 @@ static int nfs_parse_simple_hostname(const char *dev,
> if (pathname) {
> *pathname = strndup(colon, path_len);
> if (*pathname == NULL) {
> - free(*hostname);
> + if (hostname)
> + free(*hostname);
> return nfs_pdn_nomem_err();
> }
> }
>

2015-12-03 15:21:31

by Vivek Trivedi

[permalink] [raw]
Subject: Re: [PATCH 1/2] nfs-utils: libnsm.a: do not close file if open failed

thanks for review!
actually, it fixed a coverity issue a while back, so I thought of
sharing this minor change.

thanks!

On Wed, Dec 2, 2015 at 9:41 PM, Steve Dickson <[email protected]> wrote:
>
>
> On 12/02/2015 06:16 AM, Vivek Trivedi wrote:
>> If file open failed, no need to issue close system call in
>> nsm_get_state and closeall.
> I guess this makes sense... but what problem is this patch fixing?
>
> steved.
>
>>
>> Signed-off-by: Vivek Trivedi <[email protected]>
>> ---
>> support/nfs/closeall.c | 3 ++-
>> support/nsm/file.c | 3 ++-
>> 2 files changed, 4 insertions(+), 2 deletions(-)
>>
>> diff --git a/support/nfs/closeall.c b/support/nfs/closeall.c
>> index 38fb162..a69bf35 100644
>> --- a/support/nfs/closeall.c
>> +++ b/support/nfs/closeall.c
>> @@ -31,6 +31,7 @@ closeall(int min)
>> } else {
>> int fd = sysconf(_SC_OPEN_MAX);
>> while (--fd >= min)
>> - (void) close(fd);
>> + if(fd >= 0)
>> + (void) close(fd);
>> }
>> }
>> diff --git a/support/nsm/file.c b/support/nsm/file.c
>> index 4711c2c..7a8b504 100644
>> --- a/support/nsm/file.c
>> +++ b/support/nsm/file.c
>> @@ -536,7 +536,8 @@ nsm_get_state(_Bool update)
>> state++;
>>
>> update:
>> - (void)close(fd);
>> + if(fd >= 0)
>> + (void)close(fd);
>>
>> if (update) {
>> state += 2;
>>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-nfs" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html

2015-12-03 15:22:30

by Vivek Trivedi

[permalink] [raw]
Subject: Re: [PATCH 2/2] nfs-utils: mount.nfs: fix null pointer derefernce in nfs_parse_simple_hostname

thanks for review!
actually, it fixed a coverity issue a while back, so I thought of
sharing this minor change.

thanks!

On Wed, Dec 2, 2015 at 9:46 PM, Steve Dickson <[email protected]> wrote:
> hello,
>
> On 12/02/2015 06:16 AM, Vivek Trivedi wrote:
>> In function nfs_parse_simple_hostname, hostname can be NULL,
>> dereferncing it while passing it to free(*hostname) may result in segfault.
> Again I can see the logic but I wondering why/how a NULL hostname
> is being passed. I don't see how a NULL hostname can be passed
> in esp during a mount....
>
> steved.
>
>>
>> Signed-off-by: Vivek Trivedi <[email protected]>
>> ---
>> utils/mount/parse_dev.c | 3 ++-
>> 1 file changed, 2 insertions(+), 1 deletion(-)
>>
>> diff --git a/utils/mount/parse_dev.c b/utils/mount/parse_dev.c
>> index d64b83d..0d3bcb9 100644
>> --- a/utils/mount/parse_dev.c
>> +++ b/utils/mount/parse_dev.c
>> @@ -118,7 +118,8 @@ static int nfs_parse_simple_hostname(const char *dev,
>> if (pathname) {
>> *pathname = strndup(colon, path_len);
>> if (*pathname == NULL) {
>> - free(*hostname);
>> + if (hostname)
>> + free(*hostname);
>> return nfs_pdn_nomem_err();
>> }
>> }
>>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-nfs" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html

2015-12-12 12:11:57

by Steve Dickson

[permalink] [raw]
Subject: Re: [PATCH 1/2] nfs-utils: libnsm.a: do not close file if open failed



On 12/02/2015 06:16 AM, Vivek Trivedi wrote:
> If file open failed, no need to issue close system call in
> nsm_get_state and closeall.
>
> Signed-off-by: Vivek Trivedi <[email protected]>
Committed...

steved.

> ---
> support/nfs/closeall.c | 3 ++-
> support/nsm/file.c | 3 ++-
> 2 files changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/support/nfs/closeall.c b/support/nfs/closeall.c
> index 38fb162..a69bf35 100644
> --- a/support/nfs/closeall.c
> +++ b/support/nfs/closeall.c
> @@ -31,6 +31,7 @@ closeall(int min)
> } else {
> int fd = sysconf(_SC_OPEN_MAX);
> while (--fd >= min)
> - (void) close(fd);
> + if(fd >= 0)
> + (void) close(fd);
> }
> }
> diff --git a/support/nsm/file.c b/support/nsm/file.c
> index 4711c2c..7a8b504 100644
> --- a/support/nsm/file.c
> +++ b/support/nsm/file.c
> @@ -536,7 +536,8 @@ nsm_get_state(_Bool update)
> state++;
>
> update:
> - (void)close(fd);
> + if(fd >= 0)
> + (void)close(fd);
>
> if (update) {
> state += 2;
>

2015-12-12 12:12:18

by Steve Dickson

[permalink] [raw]
Subject: Re: [PATCH 2/2] nfs-utils: mount.nfs: fix null pointer derefernce in nfs_parse_simple_hostname



On 12/02/2015 06:16 AM, Vivek Trivedi wrote:
> In function nfs_parse_simple_hostname, hostname can be NULL,
> dereferncing it while passing it to free(*hostname) may result in segfault.
>
> Signed-off-by: Vivek Trivedi <[email protected]>
Committed...

steved.

> ---
> utils/mount/parse_dev.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/utils/mount/parse_dev.c b/utils/mount/parse_dev.c
> index d64b83d..0d3bcb9 100644
> --- a/utils/mount/parse_dev.c
> +++ b/utils/mount/parse_dev.c
> @@ -118,7 +118,8 @@ static int nfs_parse_simple_hostname(const char *dev,
> if (pathname) {
> *pathname = strndup(colon, path_len);
> if (*pathname == NULL) {
> - free(*hostname);
> + if (hostname)
> + free(*hostname);
> return nfs_pdn_nomem_err();
> }
> }
>