1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-03-25 10:50:08 +03:00

error: Don't move past current position

Make sure that we never move past the current position in
xmlParserPrintFileContextInternal.

Found with libFuzzer and -fsanitize=implicit-conversion.
This commit is contained in:
Nick Wellnhofer 2023-01-22 12:00:59 +01:00
parent 608c65bb8e
commit d9a8dab3a3

View File

@ -190,10 +190,12 @@ xmlParserPrintFileContextInternal(xmlParserInputPtr input ,
}
n = 0;
/* search backwards for beginning-of-line (to max buff size) */
while ((n++ < (sizeof(content)-1)) && (cur > base) &&
(*(cur) != '\n') && (*(cur) != '\r'))
while ((n < sizeof(content) - 1) && (cur > base) &&
(*cur != '\n') && (*cur != '\r')) {
cur--;
if ((*(cur) == '\n') || (*(cur) == '\r')) {
n++;
}
if ((n > 0) && ((*cur == '\n') || (*cur == '\r'))) {
cur++;
} else {
/* skip over continuation bytes */