From 0e2ea2fa6c8bd4ba16c8482e3ded7a434d2f510f Mon Sep 17 00:00:00 2001 From: Disconnect3d Date: Mon, 13 Apr 2020 16:01:47 +0200 Subject: [PATCH 1/2] Fix incorrect html entities parsing in ZNCString.cpp This PR fixes wrong size argument passed to `strncasecmp` function when it was invoked to check if the string contains HTML entities. --- src/ZNCString.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ZNCString.cpp b/src/ZNCString.cpp index 6eb762f1..1162e1c5 100644 --- a/src/ZNCString.cpp +++ b/src/ZNCString.cpp @@ -294,13 +294,13 @@ CString CString::Escape_n(EEscape eFrom, EEscape eTo) const { } if (ch == 0) { - if (!strncasecmp((const char*)&pTmp, "<", 2)) + if (!strncasecmp((const char*)&pTmp, "<", 4)) ch = '<'; - else if (!strncasecmp((const char*)&pTmp, ">", 2)) + else if (!strncasecmp((const char*)&pTmp, ">", 4)) ch = '>'; - else if (!strncasecmp((const char*)&pTmp, """, 4)) + else if (!strncasecmp((const char*)&pTmp, """, 6)) ch = '"'; - else if (!strncasecmp((const char*)&pTmp, "&", 3)) + else if (!strncasecmp((const char*)&pTmp, "&", 5)) ch = '&'; } From e801c497409ce01faf91259b11b6cbd7b8346501 Mon Sep 17 00:00:00 2001 From: Alexey Sokolov Date: Mon, 20 Apr 2020 20:51:07 +0100 Subject: [PATCH 2/2] Test #1715 --- test/StringTest.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/StringTest.cpp b/test/StringTest.cpp index aef7881d..7c2efec2 100644 --- a/test/StringTest.cpp +++ b/test/StringTest.cpp @@ -53,6 +53,8 @@ TEST_F(EscapeTest, Test) { testString("&<>", "%26%3C%3E", "&<>", "&<>", "&<>"); testString(" ;", "+%3B", " ;", " ;", "\\s\\:"); // clang-format on + EXPECT_EQ(CString("a<.b>c").Escape_n(CString::EHTML, CString::EASCII), + "a<.b>c"); } TEST(StringTest, Bool) { @@ -199,8 +201,8 @@ TEST(StringTest, Equals) { TEST(StringTest, Find) { EXPECT_EQ(CString("Hello, I'm Bob").Find("Hello"), 0u); - EXPECT_EQ( - CString("Hello, I'm Bob").Find("Hello", CString::CaseInsensitive), 0u); + EXPECT_EQ(CString("Hello, I'm Bob").Find("Hello", CString::CaseInsensitive), + 0u); EXPECT_EQ(CString("Hello, I'm Bob").Find("Hello", CString::CaseSensitive), 0u);