[sheepdog] [PATCH 1/2] farm: fix possible null defererence

Liu Yuan namei.unix at gmail.com
Tue Sep 24 19:43:27 CEST 2013


if trunk_file_read() return NULL, we should return immediately.

Signed-off-by: Liu Yuan <namei.unix at gmail.com>
---
 dog/farm/trunk.c |    6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/dog/farm/trunk.c b/dog/farm/trunk.c
index 91f293e..0515560 100644
--- a/dog/farm/trunk.c
+++ b/dog/farm/trunk.c
@@ -61,8 +61,10 @@ int for_each_entry_in_trunk(unsigned char *trunk_sha1,
 	int ret = -1;
 
 	trunk = trunk_file_read(trunk_sha1);
-	if (!trunk)
-		goto out;
+	if (!trunk) {
+		sd_err("failed to read trunk");
+		return ret;
+	}
 
 	total_count = trunk->nr_entries;
 	entry = trunk->entries;
-- 
1.7.9.5




More information about the sheepdog mailing list