You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rocketmq.apache.org by di...@apache.org on 2020/02/25 03:32:39 UTC

[rocketmq-client-cpp] branch master updated: fix(test): fix the heap-buffer-overflow bug and bad/invalid test cases.

This is an automated email from the ASF dual-hosted git repository.

dinglei pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/rocketmq-client-cpp.git


The following commit(s) were added to refs/heads/master by this push:
     new 6907a7b  fix(test): fix the heap-buffer-overflow bug and bad/invalid test cases.
6907a7b is described below

commit 6907a7b896693f0c77b84eaa2fa9bed31886d54e
Author: yizhe.wcm <42...@users.noreply.github.com>
AuthorDate: Tue Feb 25 11:32:28 2020 +0800

    fix(test): fix the heap-buffer-overflow bug and bad/invalid test cases.
    
    (1)Fix bad and invalid test cases.
    (2)Add a test case for boundary 0.
    (3)Fix the heap-after-free bug.
---
 test/src/common/MemoryBlockTest.cpp | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/test/src/common/MemoryBlockTest.cpp b/test/src/common/MemoryBlockTest.cpp
index bfd7b92..4b72d6c 100644
--- a/test/src/common/MemoryBlockTest.cpp
+++ b/test/src/common/MemoryBlockTest.cpp
@@ -48,8 +48,8 @@ TEST(memoryBlock, init) {
 
   char* buf = (char*)malloc(sizeof(char) * 9);
   strcpy(buf, "RocketMQ");
-  MemoryBlock fiveMemoryBlock(buf, -1);
-  EXPECT_EQ(fiveMemoryBlock.getSize(), -1);
+  MemoryBlock fiveMemoryBlock(buf, 0);
+  EXPECT_EQ(fiveMemoryBlock.getSize(), 0);
   EXPECT_TRUE(fiveMemoryBlock.getData() == nullptr);
 
   char* bufNull = NULL;
@@ -57,6 +57,7 @@ TEST(memoryBlock, init) {
   EXPECT_EQ(sixMemoryBlock.getSize(), 16);
   EXPECT_TRUE(sixMemoryBlock.getData() != nullptr);
 
+  buf = (char*)realloc(buf, 20);
   MemoryBlock sevenMemoryBlock(buf, 20);
   EXPECT_EQ(sevenMemoryBlock.getSize(), 20);
   sevenMemoryBlock.getData();