Commit 50f06b3e authored by Nick Wellnhofer's avatar Nick Wellnhofer

Fix out-of-bounds read with 'xmllint --htmlout'

Make sure that truncated UTF-8 sequences don't cause an out-of-bounds
array access.

Thanks to @SuhwanSong and the Agency for Defense Development (ADD) for
the report.

Fixes #178.
parent 1abf2967
......@@ -528,6 +528,12 @@ static void
xmlHTMLEncodeSend(void) {
char *result;
/*
* xmlEncodeEntitiesReentrant assumes valid UTF-8, but the buffer might
* end with a truncated UTF-8 sequence. This is a hack to at least avoid
* an out-of-bounds read.
*/
memset(&buffer[sizeof(buffer)-4], 0, 4);
result = (char *) xmlEncodeEntitiesReentrant(NULL, BAD_CAST buffer);
if (result) {
xmlGenericError(xmlGenericErrorContext, "%s", result);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment