[sheepdog] [PATCH] sheep/object_cache: fix potential crash in object_cache_remove

Ruoyu liangry at ucweb.com
Mon Apr 21 12:11:01 CEST 2014


If object is not found, entry reference to NULL, the below statement
will cause a crash.
struct object_cache *oc = entry->oc;

Signed-off-by: Ruoyu <liangry at ucweb.com>
---
 sheep/object_cache.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/sheep/object_cache.c b/sheep/object_cache.c
index d51d459..728eacc 100644
--- a/sheep/object_cache.c
+++ b/sheep/object_cache.c
@@ -1293,12 +1293,14 @@ int object_cache_remove(uint64_t oid)
 {
 	/* Inc the entry refcount to exclude the reclaimer */
 	struct object_cache_entry *entry = oid_to_entry(oid);
-	struct object_cache *oc = entry->oc;
+	struct object_cache *oc;
 	int ret;
 
 	if (!entry)
 		return SD_RES_NO_OBJ;
 
+	oc = entry->oc;
+
 	sd_debug("%" PRIx64, oid);
 	while (refcount_read(&entry->refcnt) > 1)
 		usleep(100000); /* Object might be in push */
-- 
1.8.3.2





More information about the sheepdog mailing list