1From d9a8dab3a3ba980f1efc1366c1b9a3a2434dcabd Mon Sep 17 00:00:00 2001 2From: Nick Wellnhofer <wellnhofer@aevum.de> 3Date: Sun, 22 Jan 2023 12:00:59 +0100 4Subject: [PATCH] error: Don't move past current position 5 6Make sure that we never move past the current position in 7xmlParserPrintFileContextInternal. 8 9Found with libFuzzer and -fsanitize=implicit-conversion. 10 11Reference:https://github.com/GNOME/libxml2/commit/d9a8dab3a3ba980f1efc1366c1b9a3a2434dcabd 12Conflict:NA 13--- 14 error.c | 8 +++++--- 15 1 file changed, 5 insertions(+), 3 deletions(-) 16 17diff --git a/error.c b/error.c 18index fe9a7e2..5eee72a 100644 19--- a/error.c 20+++ b/error.c 21@@ -188,10 +188,12 @@ xmlParserPrintFileContextInternal(xmlParserInputPtr input , 22 } 23 n = 0; 24 /* search backwards for beginning-of-line (to max buff size) */ 25- while ((n++ < (sizeof(content)-1)) && (cur > base) && 26- (*(cur) != '\n') && (*(cur) != '\r')) 27+ while ((n < sizeof(content) - 1) && (cur > base) && 28+ (*cur != '\n') && (*cur != '\r')) { 29 cur--; 30- if ((*(cur) == '\n') || (*(cur) == '\r')) { 31+ n++; 32+ } 33+ if ((n > 0) && ((*cur == '\n') || (*cur == '\r'))) { 34 cur++; 35 } else { 36 /* skip over continuation bytes */ 37-- 382.27.0 39 40