mirror of
https://gitlab.gnome.org/GNOME/libxml2
synced 2025-03-28 21:33:13 +00:00
malloc-fail: Report malloc failure in xmlXPathTranslateFunction
This commit is contained in:
parent
69d88566b6
commit
6ae98ebc64
74
xpath.c
74
xpath.c
@ -8413,42 +8413,46 @@ xmlXPathTranslateFunction(xmlXPathParserContextPtr ctxt, int nargs) {
|
||||
goto error;
|
||||
|
||||
target = xmlBufCreate();
|
||||
if (target) {
|
||||
max = xmlUTF8Strlen(to->stringval);
|
||||
for (cptr = str->stringval; (ch=*cptr); ) {
|
||||
offset = xmlUTF8Strloc(from->stringval, cptr);
|
||||
if (offset >= 0) {
|
||||
if (offset < max) {
|
||||
point = xmlUTF8Strpos(to->stringval, offset);
|
||||
if (point)
|
||||
xmlBufAdd(target, point, xmlUTF8Strsize(point, 1));
|
||||
}
|
||||
} else
|
||||
xmlBufAdd(target, cptr, xmlUTF8Strsize(cptr, 1));
|
||||
|
||||
/* Step to next character in input */
|
||||
cptr++;
|
||||
if ( ch & 0x80 ) {
|
||||
/* if not simple ascii, verify proper format */
|
||||
if ( (ch & 0xc0) != 0xc0 ) {
|
||||
xmlGenericError(xmlGenericErrorContext,
|
||||
"xmlXPathTranslateFunction: Invalid UTF8 string\n");
|
||||
/* not asserting an XPath error is probably better */
|
||||
break;
|
||||
}
|
||||
/* then skip over remaining bytes for this char */
|
||||
while ( (ch <<= 1) & 0x80 )
|
||||
if ( (*cptr++ & 0xc0) != 0x80 ) {
|
||||
xmlGenericError(xmlGenericErrorContext,
|
||||
"xmlXPathTranslateFunction: Invalid UTF8 string\n");
|
||||
/* not asserting an XPath error is probably better */
|
||||
break;
|
||||
}
|
||||
if (ch & 0x80) /* must have had error encountered */
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (target == NULL) {
|
||||
xmlXPathPErrMemory(ctxt, NULL);
|
||||
goto error;
|
||||
}
|
||||
|
||||
max = xmlUTF8Strlen(to->stringval);
|
||||
for (cptr = str->stringval; (ch=*cptr); ) {
|
||||
offset = xmlUTF8Strloc(from->stringval, cptr);
|
||||
if (offset >= 0) {
|
||||
if (offset < max) {
|
||||
point = xmlUTF8Strpos(to->stringval, offset);
|
||||
if (point)
|
||||
xmlBufAdd(target, point, xmlUTF8Strsize(point, 1));
|
||||
}
|
||||
} else
|
||||
xmlBufAdd(target, cptr, xmlUTF8Strsize(cptr, 1));
|
||||
|
||||
/* Step to next character in input */
|
||||
cptr++;
|
||||
if ( ch & 0x80 ) {
|
||||
/* if not simple ascii, verify proper format */
|
||||
if ( (ch & 0xc0) != 0xc0 ) {
|
||||
xmlGenericError(xmlGenericErrorContext,
|
||||
"xmlXPathTranslateFunction: Invalid UTF8 string\n");
|
||||
/* not asserting an XPath error is probably better */
|
||||
break;
|
||||
}
|
||||
/* then skip over remaining bytes for this char */
|
||||
while ( (ch <<= 1) & 0x80 )
|
||||
if ( (*cptr++ & 0xc0) != 0x80 ) {
|
||||
xmlGenericError(xmlGenericErrorContext,
|
||||
"xmlXPathTranslateFunction: Invalid UTF8 string\n");
|
||||
/* not asserting an XPath error is probably better */
|
||||
break;
|
||||
}
|
||||
if (ch & 0x80) /* must have had error encountered */
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
valuePush(ctxt, xmlXPathCacheNewString(ctxt, xmlBufContent(target)));
|
||||
xmlBufFree(target);
|
||||
error:
|
||||
|
Loading…
x
Reference in New Issue
Block a user