]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
test/libcephfs: avoid buffer overflow when testing ceph_getdents() 14671/head
authorYan, Zheng <zyan@redhat.com>
Wed, 15 Feb 2017 03:45:26 +0000 (11:45 +0800)
committerNathan Cutler <ncutler@suse.com>
Thu, 20 Apr 2017 10:55:48 +0000 (12:55 +0200)
The buffer size should be at least "2 * sizeof(struct dirent)".
Otherwise, the code that checks dentry '..' overflow.

Fixes: http://tracker.ceph.com/issues/18941
Signed-off-by: "Yan, Zheng" <zyan@redhat.com>
(cherry picked from commit fa6671345b8f3a82dcd232f99e55a982b0a641f1)

src/test/libcephfs/test.cc

index 42b02f11d7bf070ed8cc6405041db57a771ae1d0..df7db20a70c4b41ae636ba48b320853b10bbca4e 100644 (file)
@@ -361,7 +361,7 @@ TEST(LibCephFS, DirLs) {
 
   // test getdents
   struct dirent *getdents_entries;
-  getdents_entries = (struct dirent *)malloc(r * sizeof(*getdents_entries));
+  getdents_entries = (struct dirent *)malloc((r + 2) * sizeof(*getdents_entries));
 
   int count = 0;
   std::vector<std::string> found;