]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
test/libcephfs: avoid buffer overflow when testing ceph_getdents() 13429/head
authorYan, Zheng <zyan@redhat.com>
Wed, 15 Feb 2017 03:45:26 +0000 (11:45 +0800)
committerYan, Zheng <zyan@redhat.com>
Wed, 15 Feb 2017 04:01:22 +0000 (12:01 +0800)
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>
src/test/libcephfs/test.cc

index eca2ef026ce95c6b2cc866a62a7865e064c7a12c..3bd812b3bdc89c49ecf0fbcefc0b820afae07a29 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;