summaryrefslogtreecommitdiffstats
path: root/libglusterfs
diff options
context:
space:
mode:
authorShehjar Tikoo <shehjart@gluster.com>2009-06-03 01:05:34 +0000
committerAnand V. Avati <avati@dev.gluster.com>2009-06-08 06:31:56 -0700
commit6a0ab0b2edca89da524b7dcf29994033f98c8552 (patch)
tree242883f0ab4f8a683fd3529a580843175cf27ae5 /libglusterfs
parent4fa1211b0fa015b49e662b26327c306f42299bbb (diff)
libglusterfs: Add empty and NULL dirents list checks
These checks are needed in case a higher layer intends to delink the dirent list and passes a NULL pointer to fop_readdir_cbk_stub for the entries parameter. Consequently, the gf_dirent_free must guard against an empty list because the stub that is passed to it mgiht have an empty dirent list. Signed-off-by: Anand V. Avati <avati@dev.gluster.com>
Diffstat (limited to 'libglusterfs')
-rw-r--r--libglusterfs/src/call-stub.c6
-rw-r--r--libglusterfs/src/gf-dirent.c6
2 files changed, 12 insertions, 0 deletions
diff --git a/libglusterfs/src/call-stub.c b/libglusterfs/src/call-stub.c
index 63fe5be558f..2447bf1aed3 100644
--- a/libglusterfs/src/call-stub.c
+++ b/libglusterfs/src/call-stub.c
@@ -1992,6 +1992,12 @@ fop_readdir_cbk_stub (call_frame_t *frame,
stub->args.readdir_cbk.op_errno = op_errno;
INIT_LIST_HEAD (&stub->args.readdir_cbk.entries.list);
+ /* This check must come after the init of head above
+ * so we're sure the list is empty for list_empty.
+ */
+ if (!entries)
+ goto out;
+
if (op_ret > 0) {
list_for_each_entry (entry, &entries->list, list) {
stub_entry = gf_dirent_for_name (entry->d_name);
diff --git a/libglusterfs/src/gf-dirent.c b/libglusterfs/src/gf-dirent.c
index 2023c19836f..b321dfc10e0 100644
--- a/libglusterfs/src/gf-dirent.c
+++ b/libglusterfs/src/gf-dirent.c
@@ -76,6 +76,12 @@ gf_dirent_free (gf_dirent_t *entries)
gf_dirent_t *entry = NULL;
gf_dirent_t *tmp = NULL;
+ if (!entries)
+ return;
+
+ if (list_empty (&entries->list))
+ return;
+
list_for_each_entry_safe (entry, tmp, &entries->list, list) {
list_del (&entry->list);
FREE (entry);