* [PATCH] nfs-utils: Fix the error handling if the lseek fails
@ 2019-08-01 13:32 Alice J Mitchell
2019-08-01 16:21 ` Steve Dickson
0 siblings, 1 reply; 2+ messages in thread
From: Alice J Mitchell @ 2019-08-01 13:32 UTC (permalink / raw)
To: linux-nfs; +Cc: Steve Dickson
The error case when lseek returns a negative value was not correctly handled,
and the error cleanup routine was potentially leaking memory also.
Signed-off-by: Alice J Mitchell <ajmitchell@redhat.com>
---
support/nfs/conffile.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/support/nfs/conffile.c b/support/nfs/conffile.c
index b6400be..6ba8a35 100644
--- a/support/nfs/conffile.c
+++ b/support/nfs/conffile.c
@@ -500,7 +500,7 @@ conf_readfile(const char *path)
if ((stat (path, &sb) == 0) || (errno != ENOENT)) {
char *new_conf_addr = NULL;
- size_t sz = sb.st_size;
+ off_t sz;
int fd = open (path, O_RDONLY, 0);
if (fd == -1) {
@@ -517,6 +517,11 @@ conf_readfile(const char *path)
/* only after we have the lock, check the file size ready to read it */
sz = lseek(fd, 0, SEEK_END);
+ if (sz < 0) {
+ xlog_warn("conf_readfile: unable to determine file size: %s",
+ strerror(errno));
+ goto fail;
+ }
lseek(fd, 0, SEEK_SET);
new_conf_addr = malloc(sz+1);
@@ -2162,6 +2167,7 @@ conf_write(const char *filename, const char *section, const char *arg,
ret = 0;
cleanup:
+ flush_outqueue(&inqueue, NULL);
flush_outqueue(&outqueue, NULL);
if (buff)
--
1.8.3.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] nfs-utils: Fix the error handling if the lseek fails
2019-08-01 13:32 [PATCH] nfs-utils: Fix the error handling if the lseek fails Alice J Mitchell
@ 2019-08-01 16:21 ` Steve Dickson
0 siblings, 0 replies; 2+ messages in thread
From: Steve Dickson @ 2019-08-01 16:21 UTC (permalink / raw)
To: Alice J Mitchell, linux-nfs
On 8/1/19 9:32 AM, Alice J Mitchell wrote:
> The error case when lseek returns a negative value was not correctly handled,
> and the error cleanup routine was potentially leaking memory also.
>
> Signed-off-by: Alice J Mitchell <ajmitchell@redhat.com>
Committed...
steved.
> ---
> support/nfs/conffile.c | 8 +++++++-
> 1 file changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/support/nfs/conffile.c b/support/nfs/conffile.c
> index b6400be..6ba8a35 100644
> --- a/support/nfs/conffile.c
> +++ b/support/nfs/conffile.c
> @@ -500,7 +500,7 @@ conf_readfile(const char *path)
>
> if ((stat (path, &sb) == 0) || (errno != ENOENT)) {
> char *new_conf_addr = NULL;
> - size_t sz = sb.st_size;
> + off_t sz;
> int fd = open (path, O_RDONLY, 0);
>
> if (fd == -1) {
> @@ -517,6 +517,11 @@ conf_readfile(const char *path)
>
> /* only after we have the lock, check the file size ready to read it */
> sz = lseek(fd, 0, SEEK_END);
> + if (sz < 0) {
> + xlog_warn("conf_readfile: unable to determine file size: %s",
> + strerror(errno));
> + goto fail;
> + }
> lseek(fd, 0, SEEK_SET);
>
> new_conf_addr = malloc(sz+1);
> @@ -2162,6 +2167,7 @@ conf_write(const char *filename, const char *section, const char *arg,
> ret = 0;
>
> cleanup:
> + flush_outqueue(&inqueue, NULL);
> flush_outqueue(&outqueue, NULL);
>
> if (buff)
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2019-08-01 16:21 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-01 13:32 [PATCH] nfs-utils: Fix the error handling if the lseek fails Alice J Mitchell
2019-08-01 16:21 ` Steve Dickson
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).