]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
test/libcephfs: avoid buffer overflow when testing ceph_getdents() 14571/head
authorYan, Zheng <zyan@redhat.com>
Wed, 15 Feb 2017 03:45:26 +0000 (11:45 +0800)
committerNathan Cutler <ncutler@suse.com>
Fri, 14 Apr 2017 21:54:00 +0000 (23:54 +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 e2864f8e964cc1e37034163872928a13c688f813..283d46ff25651402a651edece0380329be8961cc 100644 (file)
@@ -362,7 +362,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;