Skip to content

Commit

Permalink
Add XML to invalid XML error message.
Browse files Browse the repository at this point in the history
There have been cases where pgBackRest has failed on invalid XML but it is not possible to determine what was wrong with the XML.

This will only work for XML up to about 8KiB (which is the error message limit) but it should work in most cases.
  • Loading branch information
dwsteele committed Feb 23, 2022
1 parent 10038db commit 67bdf07
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/common/type/xml.c
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ xmlDocumentNewBuf(const Buffer *buffer)
*this = (XmlDocument){{0}}; // Extra braces are required for older gcc versions

if ((this->xml = xmlReadMemory((const char *)bufPtrConst(buffer), (int)bufUsed(buffer), "noname.xml", NULL, 0)) == NULL)
THROW_FMT(FormatError, "invalid xml");
THROW_FMT(FormatError, "invalid xml in %zu byte(s):\n%s", bufUsed(buffer), strZ(strNewBuf(buffer)));

// Set callback to ensure xml document is freed
memContextCallbackSet(objMemContext(this), xmlDocumentFreeResource, this);
Expand Down
3 changes: 2 additions & 1 deletion test/src/module/common/typeXmlTest.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ testRun(void)
// *****************************************************************************************************************************
if (testBegin("xml*()"))
{
TEST_ERROR(xmlDocumentNewBuf(bufNewC(BOGUS_STR, strlen(BOGUS_STR))), FormatError, "invalid xml");
TEST_ERROR(
xmlDocumentNewBuf(bufNewC(BOGUS_STR, strlen(BOGUS_STR))), FormatError, "invalid xml in 5 byte(s):\nBOGUS");

XmlDocument *xmlDocument = NULL;
TEST_ASSIGN(
Expand Down

0 comments on commit 67bdf07

Please sign in to comment.