Patchwork [03/12] fedfsd: don't return freed memory through **pathname parameter, ...

login
register
mail settings
Submitter Chuck Lever
Date Dec. 13, 2011, 10:51 p.m.
Message ID <20111213225122.15402.42204.stgit@degas.1015granger.net>
Download mbox | patch
Permalink /patch/131203/
State Accepted
Headers show

Comments

Chuck Lever - Dec. 13, 2011, 10:51 p.m.
From: Jim Meyering <meyering@redhat.com>

even though upon error it will not be used.
* src/fedfsd/svc.c (fedfsd_pathwalk): On an error path, don't
set *pathname at all, and certainly not to a just-freed pointer.
Spotted by coverity.

Introduced by commit 0520ee72: "Initial commit," (March 29, 2011).

Signed-off-by: Jim Meyering <meyering@redhat.com>
---

 src/fedfsd/svc.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)

Patch

diff --git a/src/fedfsd/svc.c b/src/fedfsd/svc.c
index 132be70..12940c7 100644
--- a/src/fedfsd/svc.c
+++ b/src/fedfsd/svc.c
@@ -316,10 +316,12 @@  fedfsd_pathwalk(const FedFsPathName fpath, char **pathname)
 		xlog(D_CALL, "%s: Zero-component pathname", __func__);
 		strcat(result, "/");
 		retval = fedfsd_pathwalk_check_term(result);
-		if (retval != FEDFS_OK)
+		if (retval != FEDFS_OK) {
 			free(result);
+			return retval;
+		}
 		*pathname = result;
-		return retval;
+		return FEDFS_OK;
 	}
 
 	for (i = 0; i < fpath.FedFsPathName_len; i++) {