diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2018-06-13 10:21:21 +0200 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2018-06-13 16:05:26 +0200 |
commit | 98db90e2ccd7cefaa5094c2d1d2af8cb10b4a867 (patch) | |
tree | e186fa1b00f10dd78d6235ccbab87b067385439e /helpcompiler | |
parent | 39e75712b253430489089ed1d70f2ead1d7f6aa6 (diff) |
Don't create std::string from nullptr
...which violates the ctor's preconditions, so is UB. Also, the "XML Help
Document Type Definition" appendix of
<http://documentation.openoffice.org/online_help/OOo2HelpAuthoring.pdf> states
that "branch" and "id" attributes are #REQUIRED for the "bookmark" element.
(There's probably further cases in the surrounding code where a std::string is
created from a potentially null argument, which would benefit from similar
fixes.)
Change-Id: I414576d13de784de1290951bcdd5e3ecb51f9cb8
Reviewed-on: https://gerrit.libreoffice.org/55735
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'helpcompiler')
-rw-r--r-- | helpcompiler/source/HelpCompiler.cxx | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/helpcompiler/source/HelpCompiler.cxx b/helpcompiler/source/HelpCompiler.cxx index 1013c8d8e81a..8cfdcecfa539 100644 --- a/helpcompiler/source/HelpCompiler.cxx +++ b/helpcompiler/source/HelpCompiler.cxx @@ -325,10 +325,18 @@ void myparser::traverse( xmlNodePtr parentNode ) else if (!strcmp(reinterpret_cast<const char*>(test->name), "bookmark")) { xmlChar *branchxml = xmlGetProp(test, reinterpret_cast<const xmlChar*>("branch")); - xmlChar *idxml = xmlGetProp(test, reinterpret_cast<const xmlChar*>("id")); + if (branchxml == nullptr) { + throw HelpProcessingException( + HelpProcessingErrorClass::XmlParsing, "bookmark lacks branch attribute"); + } std::string branch(reinterpret_cast<char*>(branchxml)); - std::string anchor(reinterpret_cast<char*>(idxml)); xmlFree (branchxml); + xmlChar *idxml = xmlGetProp(test, reinterpret_cast<const xmlChar*>("id")); + if (idxml == nullptr) { + throw HelpProcessingException( + HelpProcessingErrorClass::XmlParsing, "bookmark lacks id attribute"); + } + std::string anchor(reinterpret_cast<char*>(idxml)); xmlFree (idxml); if (branch.compare(0, 3, "hid") == 0) |