From f671ce6c6fa619b5cea2559495b4b21920f5de73 Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Tue, 3 Jul 2012 16:32:25 +0200 Subject: glusterfsd: don't ignore tmpfile write failure (2x) In both glusterfs_volfile_reconfigure and mgmt_getspec_cbk, we fwrite to a temporary file, fflush the stream, and then rewind and read from it. However, if either the fwrite or fflush were to fail, we would have ignored a write failure and would then read and process corrupt or incomplete input. In each case, add a test of ferror so that we don't ignore the write failure. Found by inspection. Change-Id: I8e84deb7d020a907870c9da2dde5c7371ce6ddb7 BUG: 789278 Signed-off-by: Jim Meyering Reviewed-on: http://review.gluster.com/3648 Tested-by: Gluster Build System Reviewed-by: Anand Avati --- glusterfsd/src/glusterfsd-mgmt.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/glusterfsd/src/glusterfsd-mgmt.c b/glusterfsd/src/glusterfsd-mgmt.c index be84167e4f0..a98492fac7b 100644 --- a/glusterfsd/src/glusterfsd-mgmt.c +++ b/glusterfsd/src/glusterfsd-mgmt.c @@ -1473,6 +1473,9 @@ glusterfs_volfile_reconfigure (FILE *newvolfile_fp) } fwrite (oldvolfile, oldvollen, 1, oldvolfile_fp); fflush (oldvolfile_fp); + if (ferror (oldvolfile_fp)) { + goto out; + } oldvolfile_graph = glusterfs_graph_construct (oldvolfile_fp); @@ -1581,6 +1584,10 @@ mgmt_getspec_cbk (struct rpc_req *req, struct iovec *iov, int count, fwrite (rsp.spec, size, 1, tmpfp); fflush (tmpfp); + if (ferror (tmpfp)) { + ret = -1; + goto out; + } /* Check if only options have changed. No need to reload the * volfile if topology hasn't changed. -- cgit