Skip to content

[patch] tlXMLParser.cc:cdata_handler buffer overflow. #1751

@shamefulCake1

Description

@shamefulCake1

Hello,

in cdata_handler there is a call like this:

  d->cdata (std::string (s, 0, size_t (len)));

this will not work, because the prototype (char* , int start, unsigned int number) does not exist.
It will be implicitly cast to (std::string, int start, unsigned int number) , so it will run std::string constructor, which is a disaster, because s is not 0-terminated, so the strlen embedded into std::string constructor will run until the end of memory.

The following patch fixes the problem:

diff --git a/src/tl/tl/tlXMLParser.cc b/src/tl/tl/tlXMLParser.cc
index 164578ab0..b74280b4b 100644
--- a/src/tl/tl/tlXMLParser.cc
+++ b/src/tl/tl/tlXMLParser.cc
@@ -343,7 +343,7 @@ void end_element_handler (void *user_data, const XML_Char *name)
 void cdata_handler (void *user_data, const XML_Char *s, int len)
 {
   XMLParserPrivateData *d = reinterpret_cast<XMLParserPrivateData *> (user_data);
-  d->cdata (std::string (s, 0, size_t (len)));
+  d->cdata (std::string (s, size_t (len)));
 }

apply it with patch -p0 < patchname.patch.

I cannot make pull requests on github, because that requires activating 2FA, and I didn't manage to make it work.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions