1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

For #1229, fix the security risk in logger. 3.0.69

This commit is contained in:
winlin 2019-12-11 11:56:00 +08:00
parent ad70589347
commit 78da67e8d1
5 changed files with 36 additions and 4 deletions

View file

@ -64,9 +64,33 @@ VOID TEST(CoreMacroseTest, Check)
#endif
}
#define _ARRAY_INIT(buf, sz, val) \
for (int i = 0; i < (int)sz; i++) buf[i]=val
VOID TEST(CoreLogger, CheckVsnprintf)
{
char buf[1024];
EXPECT_EQ(6, sprintf(buf, "%s", "Hello!"));
if (true) {
char buf[1024];
_ARRAY_INIT(buf, sizeof(buf), 0xf);
// Return the number of characters printed.
EXPECT_EQ(6, sprintf(buf, "%s", "Hello!"));
EXPECT_EQ('H', buf[0]);
EXPECT_EQ('!', buf[5]);
EXPECT_EQ(0x0, buf[6]);
EXPECT_EQ(0xf, buf[7]);
}
if (true) {
char buf[1024];
_ARRAY_INIT(buf, sizeof(buf), 0xf);
// Return the number of characters that would have been printed if the size were unlimited.
EXPECT_EQ(6, snprintf(buf, 3, "%s", "Hello!"));
EXPECT_EQ('H', buf[0]);
EXPECT_EQ('e', buf[1]);
EXPECT_EQ(0, buf[2]);
EXPECT_EQ(0xf, buf[3]);
}
}