Skip to content

Commit e51b7b0

Browse files
authored
fix(memory): heap-buffer-overflow due to wrong use of strcpy.
1 parent b566dec commit e51b7b0

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

test/src/common/big_endianTest.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ TEST(big_endian, bigEndianObject) {
6262

6363
char* newBuf = (char*)malloc(sizeof(char) * 8);
6464
char* writeBuf = (char*)malloc(sizeof(char) * 8);
65-
strcpy(writeBuf, "RocketMQ");
65+
strncpy(writeBuf, "RocketMQ", 8);
6666
EXPECT_TRUE(writer.WriteBytes(writeBuf, (size_t)8));
6767
EXPECT_TRUE(reader.ReadBytes(newBuf, (size_t)8));
6868
EXPECT_EQ(*writeBuf, *newBuf);
@@ -76,7 +76,7 @@ TEST(big_endian, bigEndian) {
7676

7777
/*TODO
7878
char *newBuf = (char *) malloc(sizeof(char) * 8);
79-
strcpy(newBuf, "RocketMQ");
79+
strncpy(newBuf, "RocketMQ", 8);
8080
8181
char readBuf[8];
8282
rocketmq::WriteBigEndian(writeBuf, newBuf);

0 commit comments

Comments
 (0)