From bb63256b7ea1f186bbe3fae9040a6c191c9d6544 Mon Sep 17 00:00:00 2001 From: "Jose A. Rivera" Date: Wed, 22 Jan 2014 21:51:42 -0600 Subject: libgfapi: Fix pointer dereference before NULL check Call to dict_keys_join dereferences xattr before it is checked for NULL. Restructured the function to check for NULL earlier and call dict_unref only when needed. BUG: 789278 CID: 1124826 Change-Id: I732fa304ad6f3b921c589832d13f73bbd36f589c Signed-off-by: Jose A. Rivera Reviewed-on: http://review.gluster.org/6763 Tested-by: Gluster Build System Reviewed-by: Vijay Bellur --- api/src/glfs-fops.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'api') diff --git a/api/src/glfs-fops.c b/api/src/glfs-fops.c index 67d5616fe..f27287b9d 100644 --- a/api/src/glfs-fops.c +++ b/api/src/glfs-fops.c @@ -2543,23 +2543,23 @@ out: int glfs_listxattr_process (void *value, size_t size, dict_t *xattr) { - int ret = -1; - - ret = dict_keys_join (NULL, 0, xattr, NULL); + int ret = -1; - if (!value || !size) + if (!value || !size || !xattr) goto out; + ret = dict_keys_join (NULL, 0, xattr, NULL); + if (size < ret) { ret = -1; errno = ERANGE; - goto out; + } else { + dict_keys_join (value, size, xattr, NULL); } - dict_keys_join (value, size, xattr, NULL); + dict_unref (xattr); + out: - if (xattr) - dict_unref (xattr); return ret; } -- cgit