| OLD | NEW |
| 1 /* | 1 /* |
| 2 * SAX2.c : Default SAX2 handler to build a tree. | 2 * SAX2.c : Default SAX2 handler to build a tree. |
| 3 * | 3 * |
| 4 * See Copyright for the status of this software. | 4 * See Copyright for the status of this software. |
| 5 * | 5 * |
| 6 * Daniel Veillard <daniel@veillard.com> | 6 * Daniel Veillard <daniel@veillard.com> |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 | 9 |
| 10 #define IN_LIBXML | 10 #define IN_LIBXML |
| 11 #include "libxml.h" | 11 #include "libxml.h" |
| 12 #include <stdlib.h> | 12 #include <stdlib.h> |
| 13 #include <string.h> | 13 #include <string.h> |
| 14 #include <limits.h> |
| 14 #include <libxml/xmlmemory.h> | 15 #include <libxml/xmlmemory.h> |
| 15 #include <libxml/tree.h> | 16 #include <libxml/tree.h> |
| 16 #include <libxml/parser.h> | 17 #include <libxml/parser.h> |
| 17 #include <libxml/parserInternals.h> | 18 #include <libxml/parserInternals.h> |
| 18 #include <libxml/valid.h> | 19 #include <libxml/valid.h> |
| 19 #include <libxml/entities.h> | 20 #include <libxml/entities.h> |
| 20 #include <libxml/xmlerror.h> | 21 #include <libxml/xmlerror.h> |
| 21 #include <libxml/debugXML.h> | 22 #include <libxml/debugXML.h> |
| 22 #include <libxml/xmlIO.h> | 23 #include <libxml/xmlIO.h> |
| 23 #include <libxml/SAX.h> | 24 #include <libxml/SAX.h> |
| 24 #include <libxml/uri.h> | 25 #include <libxml/uri.h> |
| 25 #include <libxml/valid.h> | 26 #include <libxml/valid.h> |
| 26 #include <libxml/HTMLtree.h> | 27 #include <libxml/HTMLtree.h> |
| 27 #include <libxml/globals.h> | 28 #include <libxml/globals.h> |
| 28 | 29 |
| 30 /* Define SIZE_T_MAX unless defined through <limits.h>. */ |
| 31 #ifndef SIZE_T_MAX |
| 32 # define SIZE_T_MAX ((size_t)-1) |
| 33 #endif /* !SIZE_T_MAX */ |
| 34 |
| 29 /* #define DEBUG_SAX2 */ | 35 /* #define DEBUG_SAX2 */ |
| 30 /* #define DEBUG_SAX2_TREE */ | 36 /* #define DEBUG_SAX2_TREE */ |
| 31 | 37 |
| 32 /** | 38 /** |
| 33 * TODO: | 39 * TODO: |
| 34 * | 40 * |
| 35 * macro to flag unimplemented blocks | 41 * macro to flag unimplemented blocks |
| 36 * XML_CATALOG_PREFER user env to select between system/public prefered | 42 * XML_CATALOG_PREFER user env to select between system/public prefered |
| 37 * option. C.f. Richard Tobin <richard@cogsci.ed.ac.uk> | 43 * option. C.f. Richard Tobin <richard@cogsci.ed.ac.uk> |
| 38 *> Just FYI, I am using an environment variable XML_CATALOG_PREFER with | 44 *> Just FYI, I am using an environment variable XML_CATALOG_PREFER with |
| (...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 573 ret->ExternalID, &children); | 579 ret->ExternalID, &children); |
| 574 if (val == 0) { | 580 if (val == 0) { |
| 575 xmlAddChildList((xmlNodePtr) ret, children); | 581 xmlAddChildList((xmlNodePtr) ret, children); |
| 576 } else { | 582 } else { |
| 577 xmlFatalErrMsg(ctxt, XML_ERR_ENTITY_PROCESSING, | 583 xmlFatalErrMsg(ctxt, XML_ERR_ENTITY_PROCESSING, |
| 578 "Failure to process entity %s\n", name, NULL); | 584 "Failure to process entity %s\n", name, NULL); |
| 579 ctxt->validate = 0; | 585 ctxt->validate = 0; |
| 580 return(NULL); | 586 return(NULL); |
| 581 } | 587 } |
| 582 ret->owner = 1; | 588 ret->owner = 1; |
| 583 » ret->checked = 1; | 589 » if (ret->checked == 0) |
| 590 » ret->checked = 1; |
| 584 } | 591 } |
| 585 return(ret); | 592 return(ret); |
| 586 } | 593 } |
| 587 | 594 |
| 588 /** | 595 /** |
| 589 * xmlSAX2GetParameterEntity: | 596 * xmlSAX2GetParameterEntity: |
| 590 * @ctx: the user data (XML parser context) | 597 * @ctx: the user data (XML parser context) |
| 591 * @name: The entity name | 598 * @name: The entity name |
| 592 * | 599 * |
| 593 * Get a parameter entity by name | 600 * Get a parameter entity by name |
| (...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 950 if (ctx == NULL) return; | 957 if (ctx == NULL) return; |
| 951 | 958 |
| 952 #ifdef DEBUG_SAX | 959 #ifdef DEBUG_SAX |
| 953 xmlGenericError(xmlGenericErrorContext, | 960 xmlGenericError(xmlGenericErrorContext, |
| 954 "SAX.xmlSAX2StartDocument()\n"); | 961 "SAX.xmlSAX2StartDocument()\n"); |
| 955 #endif | 962 #endif |
| 956 if (ctxt->html) { | 963 if (ctxt->html) { |
| 957 #ifdef LIBXML_HTML_ENABLED | 964 #ifdef LIBXML_HTML_ENABLED |
| 958 if (ctxt->myDoc == NULL) | 965 if (ctxt->myDoc == NULL) |
| 959 ctxt->myDoc = htmlNewDocNoDtD(NULL, NULL); | 966 ctxt->myDoc = htmlNewDocNoDtD(NULL, NULL); |
| 967 ctxt->myDoc->properties = XML_DOC_HTML; |
| 968 ctxt->myDoc->parseFlags = ctxt->options; |
| 960 if (ctxt->myDoc == NULL) { | 969 if (ctxt->myDoc == NULL) { |
| 961 xmlSAX2ErrMemory(ctxt, "xmlSAX2StartDocument"); | 970 xmlSAX2ErrMemory(ctxt, "xmlSAX2StartDocument"); |
| 962 return; | 971 return; |
| 963 } | 972 } |
| 964 #else | 973 #else |
| 965 xmlGenericError(xmlGenericErrorContext, | 974 xmlGenericError(xmlGenericErrorContext, |
| 966 "libxml2 built without HTML support\n"); | 975 "libxml2 built without HTML support\n"); |
| 967 ctxt->errNo = XML_ERR_INTERNAL_ERROR; | 976 ctxt->errNo = XML_ERR_INTERNAL_ERROR; |
| 968 ctxt->instate = XML_PARSER_EOF; | 977 ctxt->instate = XML_PARSER_EOF; |
| 969 ctxt->disableSAX = 1; | 978 ctxt->disableSAX = 1; |
| 970 return; | 979 return; |
| 971 #endif | 980 #endif |
| 972 } else { | 981 } else { |
| 973 doc = ctxt->myDoc = xmlNewDoc(ctxt->version); | 982 doc = ctxt->myDoc = xmlNewDoc(ctxt->version); |
| 974 if (doc != NULL) { | 983 if (doc != NULL) { |
| 984 doc->properties = 0; |
| 985 if (ctxt->options & XML_PARSE_OLD10) |
| 986 doc->properties |= XML_DOC_OLD10; |
| 987 doc->parseFlags = ctxt->options; |
| 975 if (ctxt->encoding != NULL) | 988 if (ctxt->encoding != NULL) |
| 976 doc->encoding = xmlStrdup(ctxt->encoding); | 989 doc->encoding = xmlStrdup(ctxt->encoding); |
| 977 else | 990 else |
| 978 doc->encoding = NULL; | 991 doc->encoding = NULL; |
| 979 doc->standalone = ctxt->standalone; | 992 doc->standalone = ctxt->standalone; |
| 980 } else { | 993 } else { |
| 981 xmlSAX2ErrMemory(ctxt, "xmlSAX2StartDocument"); | 994 xmlSAX2ErrMemory(ctxt, "xmlSAX2StartDocument"); |
| 982 return; | 995 return; |
| 983 } | 996 } |
| 984 if ((ctxt->dictNames) && (doc != NULL)) { | 997 if ((ctxt->dictNames) && (doc != NULL)) { |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1085 name = xmlStrdup(fullname); | 1098 name = xmlStrdup(fullname); |
| 1086 } | 1099 } |
| 1087 } | 1100 } |
| 1088 if (name == NULL) { | 1101 if (name == NULL) { |
| 1089 xmlSAX2ErrMemory(ctxt, "xmlSAX2StartElement"); | 1102 xmlSAX2ErrMemory(ctxt, "xmlSAX2StartElement"); |
| 1090 if (ns != NULL) | 1103 if (ns != NULL) |
| 1091 xmlFree(ns); | 1104 xmlFree(ns); |
| 1092 return; | 1105 return; |
| 1093 } | 1106 } |
| 1094 | 1107 |
| 1108 #ifdef LIBXML_HTML_ENABLED |
| 1109 if ((ctxt->html) && |
| 1110 (value == NULL) && (htmlIsBooleanAttr(fullname))) { |
| 1111 nval = xmlStrdup(fullname); |
| 1112 value = (const xmlChar *) nval; |
| 1113 } else |
| 1114 #endif |
| 1115 { |
| 1095 #ifdef LIBXML_VALID_ENABLED | 1116 #ifdef LIBXML_VALID_ENABLED |
| 1096 /* | 1117 /* |
| 1097 * Do the last stage of the attribute normalization | 1118 * Do the last stage of the attribute normalization |
| 1098 * Needed for HTML too: | 1119 * Needed for HTML too: |
| 1099 * http://www.w3.org/TR/html4/types.html#h-6.2 | 1120 * http://www.w3.org/TR/html4/types.html#h-6.2 |
| 1100 */ | 1121 */ |
| 1101 ctxt->vctxt.valid = 1; | 1122 ctxt->vctxt.valid = 1; |
| 1102 nval = xmlValidCtxtNormalizeAttributeValue(&ctxt->vctxt, | 1123 nval = xmlValidCtxtNormalizeAttributeValue(&ctxt->vctxt, |
| 1103 » ctxt->myDoc, ctxt->node, | 1124 ctxt->myDoc, ctxt->node, |
| 1104 » » » » » fullname, value); | 1125 fullname, value); |
| 1105 if (ctxt->vctxt.valid != 1) { | 1126 if (ctxt->vctxt.valid != 1) { |
| 1106 » ctxt->valid = 0; | 1127 ctxt->valid = 0; |
| 1128 } |
| 1129 if (nval != NULL) |
| 1130 value = nval; |
| 1131 #else |
| 1132 nval = NULL; |
| 1133 #endif /* LIBXML_VALID_ENABLED */ |
| 1107 } | 1134 } |
| 1108 if (nval != NULL) | |
| 1109 value = nval; | |
| 1110 #else | |
| 1111 nval = NULL; | |
| 1112 #endif /* LIBXML_VALID_ENABLED */ | |
| 1113 | 1135 |
| 1114 /* | 1136 /* |
| 1115 * Check whether it's a namespace definition | 1137 * Check whether it's a namespace definition |
| 1116 */ | 1138 */ |
| 1117 if ((!ctxt->html) && (ns == NULL) && | 1139 if ((!ctxt->html) && (ns == NULL) && |
| 1118 (name[0] == 'x') && (name[1] == 'm') && (name[2] == 'l') && | 1140 (name[0] == 'x') && (name[1] == 'm') && (name[2] == 'l') && |
| 1119 (name[3] == 'n') && (name[4] == 's') && (name[5] == 0)) { | 1141 (name[3] == 'n') && (name[4] == 's') && (name[5] == 0)) { |
| 1120 xmlNsPtr nsret; | 1142 xmlNsPtr nsret; |
| 1121 xmlChar *val; | 1143 xmlChar *val; |
| 1122 | 1144 |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1226 if (name != NULL) | 1248 if (name != NULL) |
| 1227 xmlFree(name); | 1249 xmlFree(name); |
| 1228 if (nval != NULL) | 1250 if (nval != NULL) |
| 1229 xmlFree(nval); | 1251 xmlFree(nval); |
| 1230 if (val != value) | 1252 if (val != value) |
| 1231 xmlFree(val); | 1253 xmlFree(val); |
| 1232 return; | 1254 return; |
| 1233 } | 1255 } |
| 1234 | 1256 |
| 1235 if (ns != NULL) { | 1257 if (ns != NULL) { |
| 1236 xmlAttrPtr prop; | |
| 1237 namespace = xmlSearchNs(ctxt->myDoc, ctxt->node, ns); | 1258 namespace = xmlSearchNs(ctxt->myDoc, ctxt->node, ns); |
| 1259 |
| 1238 if (namespace == NULL) { | 1260 if (namespace == NULL) { |
| 1239 xmlNsErrMsg(ctxt, XML_NS_ERR_UNDEFINED_NAMESPACE, | 1261 xmlNsErrMsg(ctxt, XML_NS_ERR_UNDEFINED_NAMESPACE, |
| 1240 "Namespace prefix %s of attribute %s is not defined\n", | 1262 "Namespace prefix %s of attribute %s is not defined\n", |
| 1241 ns, name); | 1263 ns, name); |
| 1242 » } | 1264 » } else { |
| 1265 xmlAttrPtr prop; |
| 1243 | 1266 |
| 1244 » prop = ctxt->node->properties; | 1267 prop = ctxt->node->properties; |
| 1245 » while (prop != NULL) { | 1268 while (prop != NULL) { |
| 1246 » if (prop->ns != NULL) { | 1269 if (prop->ns != NULL) { |
| 1247 » » if ((xmlStrEqual(name, prop->name)) && | 1270 if ((xmlStrEqual(name, prop->name)) && |
| 1248 » » ((namespace == prop->ns) || | 1271 ((namespace == prop->ns) || |
| 1249 » » (xmlStrEqual(namespace->href, prop->ns->href)))) { | 1272 (xmlStrEqual(namespace->href, prop->ns->href)))) { |
| 1250 » » » xmlNsErrMsg(ctxt, XML_ERR_ATTRIBUTE_REDEFINED, | 1273 xmlNsErrMsg(ctxt, XML_ERR_ATTRIBUTE_REDEFINED, |
| 1251 » » » "Attribute %s in %s redefined\n", | 1274 "Attribute %s in %s redefined\n", |
| 1252 » » » name, namespace->href); | 1275 name, namespace->href); |
| 1253 » » ctxt->wellFormed = 0; | 1276 ctxt->wellFormed = 0; |
| 1254 » » if (ctxt->recovery == 0) ctxt->disableSAX = 1; | 1277 if (ctxt->recovery == 0) ctxt->disableSAX = 1; |
| 1255 » » goto error; | 1278 goto error; |
| 1256 » » } | 1279 } |
| 1257 » } | 1280 } |
| 1258 » prop = prop->next; | 1281 prop = prop->next; |
| 1259 » } | 1282 } |
| 1283 } |
| 1260 } else { | 1284 } else { |
| 1261 namespace = NULL; | 1285 namespace = NULL; |
| 1262 } | 1286 } |
| 1263 | 1287 |
| 1264 /* !!!!!! <a toto:arg="" xmlns:toto="http://toto.com"> */ | 1288 /* !!!!!! <a toto:arg="" xmlns:toto="http://toto.com"> */ |
| 1265 ret = xmlNewNsPropEatName(ctxt->node, namespace, name, NULL); | 1289 ret = xmlNewNsPropEatName(ctxt->node, namespace, name, NULL); |
| 1266 | 1290 |
| 1267 if (ret != NULL) { | 1291 if (ret != NULL) { |
| 1268 if ((ctxt->replaceEntities == 0) && (!ctxt->html)) { | 1292 if ((ctxt->replaceEntities == 0) && (!ctxt->html)) { |
| 1269 xmlNodePtr tmp; | 1293 xmlNodePtr tmp; |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1400 attr->prefix) == NULL)) { | 1424 attr->prefix) == NULL)) { |
| 1401 xmlChar *fulln; | 1425 xmlChar *fulln; |
| 1402 | 1426 |
| 1403 if (attr->prefix != NULL) { | 1427 if (attr->prefix != NULL) { |
| 1404 fulln = xmlStrdup(attr->prefix); | 1428 fulln = xmlStrdup(attr->prefix); |
| 1405 fulln = xmlStrcat(fulln, BAD_CAST ":"); | 1429 fulln = xmlStrcat(fulln, BAD_CAST ":"); |
| 1406 fulln = xmlStrcat(fulln, attr->name); | 1430 fulln = xmlStrcat(fulln, attr->name); |
| 1407 } else { | 1431 } else { |
| 1408 fulln = xmlStrdup(attr->name); | 1432 fulln = xmlStrdup(attr->name); |
| 1409 } | 1433 } |
| 1434 if (fulln == NULL) { |
| 1435 xmlSAX2ErrMemory(ctxt, "xmlSAX2StartElement"); |
| 1436 break; |
| 1437 } |
| 1410 | 1438 |
| 1411 /* | 1439 /* |
| 1412 * Check that the attribute is not declared in the | 1440 * Check that the attribute is not declared in the |
| 1413 * serialization | 1441 * serialization |
| 1414 */ | 1442 */ |
| 1415 att = NULL; | 1443 att = NULL; |
| 1416 if (atts != NULL) { | 1444 if (atts != NULL) { |
| 1417 i = 0; | 1445 i = 0; |
| 1418 att = atts[i]; | 1446 att = atts[i]; |
| 1419 while (att != NULL) { | 1447 while (att != NULL) { |
| 1420 if (xmlStrEqual(att, fulln)) | 1448 if (xmlStrEqual(att, fulln)) |
| 1421 break; | 1449 break; |
| 1422 i += 2; | 1450 i += 2; |
| 1423 att = atts[i]; | 1451 att = atts[i]; |
| 1424 } | 1452 } |
| 1425 } | 1453 } |
| 1426 if (att == NULL) { | 1454 if (att == NULL) { |
| 1427 xmlErrValid(ctxt, XML_DTD_STANDALONE_DEFAULTED, | 1455 xmlErrValid(ctxt, XML_DTD_STANDALONE_DEFAULTED, |
| 1428 "standalone: attribute %s on %s defaulted from external subset\n", | 1456 "standalone: attribute %s on %s defaulted from external subset\n", |
| 1429 (const char *)fulln, | 1457 (const char *)fulln, |
| 1430 (const char *)attr->elem); | 1458 (const char *)attr->elem); |
| 1431 } | 1459 } |
| 1460 xmlFree(fulln); |
| 1432 } | 1461 } |
| 1433 attr = attr->nexth; | 1462 attr = attr->nexth; |
| 1434 } | 1463 } |
| 1435 } | 1464 } |
| 1436 | 1465 |
| 1437 /* | 1466 /* |
| 1438 * Actually insert defaulted values when needed | 1467 * Actually insert defaulted values when needed |
| 1439 */ | 1468 */ |
| 1440 attr = elemDecl->attributes; | 1469 attr = elemDecl->attributes; |
| 1441 while (attr != NULL) { | 1470 while (attr != NULL) { |
| (...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1830 if (intern == NULL) { | 1859 if (intern == NULL) { |
| 1831 ret->content = xmlStrndup(str, len); | 1860 ret->content = xmlStrndup(str, len); |
| 1832 if (ret->content == NULL) { | 1861 if (ret->content == NULL) { |
| 1833 xmlSAX2ErrMemory(ctxt, "xmlSAX2TextNode"); | 1862 xmlSAX2ErrMemory(ctxt, "xmlSAX2TextNode"); |
| 1834 xmlFree(ret); | 1863 xmlFree(ret); |
| 1835 return(NULL); | 1864 return(NULL); |
| 1836 } | 1865 } |
| 1837 } else | 1866 } else |
| 1838 ret->content = (xmlChar *) intern; | 1867 ret->content = (xmlChar *) intern; |
| 1839 | 1868 |
| 1869 if (ctxt->input != NULL) |
| 1870 ret->line = ctxt->input->line; |
| 1871 |
| 1840 if ((__xmlRegisterCallbacks) && (xmlRegisterNodeDefaultValue)) | 1872 if ((__xmlRegisterCallbacks) && (xmlRegisterNodeDefaultValue)) |
| 1841 xmlRegisterNodeDefaultValue(ret); | 1873 xmlRegisterNodeDefaultValue(ret); |
| 1842 return(ret); | 1874 return(ret); |
| 1843 } | 1875 } |
| 1844 | 1876 |
| 1845 #ifdef LIBXML_VALID_ENABLED | 1877 #ifdef LIBXML_VALID_ENABLED |
| 1846 /* | 1878 /* |
| 1847 * xmlSAX2DecodeAttrEntities: | 1879 * xmlSAX2DecodeAttrEntities: |
| 1848 * @ctxt: the parser context | 1880 * @ctxt: the parser context |
| 1849 * @str: the input string | 1881 * @str: the input string |
| (...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2255 if ((ret->ns == NULL) && (xmlStrEqual(prefix, BAD_CAST "xml"))) { | 2287 if ((ret->ns == NULL) && (xmlStrEqual(prefix, BAD_CAST "xml"))) { |
| 2256 ret->ns = xmlSearchNs(ctxt->myDoc, ret, prefix); | 2288 ret->ns = xmlSearchNs(ctxt->myDoc, ret, prefix); |
| 2257 } | 2289 } |
| 2258 if (ret->ns == NULL) { | 2290 if (ret->ns == NULL) { |
| 2259 ns = xmlNewNs(ret, NULL, prefix); | 2291 ns = xmlNewNs(ret, NULL, prefix); |
| 2260 if (ns == NULL) { | 2292 if (ns == NULL) { |
| 2261 | 2293 |
| 2262 xmlSAX2ErrMemory(ctxt, "xmlSAX2StartElementNs"); | 2294 xmlSAX2ErrMemory(ctxt, "xmlSAX2StartElementNs"); |
| 2263 return; | 2295 return; |
| 2264 } | 2296 } |
| 2265 » xmlNsWarnMsg(ctxt, XML_NS_ERR_UNDEFINED_NAMESPACE, | 2297 if (prefix != NULL) |
| 2266 » » » "Namespace prefix %s was not found\n", | 2298 xmlNsWarnMsg(ctxt, XML_NS_ERR_UNDEFINED_NAMESPACE, |
| 2267 » » » prefix, NULL); | 2299 "Namespace prefix %s was not found\n", |
| 2300 prefix, NULL); |
| 2301 else |
| 2302 xmlNsWarnMsg(ctxt, XML_NS_ERR_UNDEFINED_NAMESPACE, |
| 2303 "Namespace default prefix was not found\n", |
| 2304 NULL, NULL); |
| 2268 } | 2305 } |
| 2269 } | 2306 } |
| 2270 | 2307 |
| 2271 /* | 2308 /* |
| 2272 * process all the other attributes | 2309 * process all the other attributes |
| 2273 */ | 2310 */ |
| 2274 if (nb_attributes > 0) { | 2311 if (nb_attributes > 0) { |
| 2275 for (j = 0,i = 0;i < nb_attributes;i++,j+=5) { | 2312 for (j = 0,i = 0;i < nb_attributes;i++,j+=5) { |
| 2276 xmlSAX2AttributeNs(ctxt, attributes[j], attributes[j+1], | 2313 xmlSAX2AttributeNs(ctxt, attributes[j], attributes[j+1], |
| 2277 attributes[j+3], attributes[j+4]); | 2314 attributes[j+3], attributes[j+4]); |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2438 * We try to minimaze realloc() uses and avoid copying | 2475 * We try to minimaze realloc() uses and avoid copying |
| 2439 * and recomputing length over and over. | 2476 * and recomputing length over and over. |
| 2440 */ | 2477 */ |
| 2441 if (lastChild->content == (xmlChar *)&(lastChild->properties)) { | 2478 if (lastChild->content == (xmlChar *)&(lastChild->properties)) { |
| 2442 lastChild->content = xmlStrdup(lastChild->content); | 2479 lastChild->content = xmlStrdup(lastChild->content); |
| 2443 lastChild->properties = NULL; | 2480 lastChild->properties = NULL; |
| 2444 } else if ((ctxt->nodemem == ctxt->nodelen + 1) && | 2481 } else if ((ctxt->nodemem == ctxt->nodelen + 1) && |
| 2445 (xmlDictOwns(ctxt->dict, lastChild->content))) { | 2482 (xmlDictOwns(ctxt->dict, lastChild->content))) { |
| 2446 lastChild->content = xmlStrdup(lastChild->content); | 2483 lastChild->content = xmlStrdup(lastChild->content); |
| 2447 } | 2484 } |
| 2485 if (((size_t)ctxt->nodelen + (size_t)len > XML_MAX_TEXT_LENGTH) && |
| 2486 ((ctxt->options & XML_PARSE_HUGE) == 0)) { |
| 2487 xmlSAX2ErrMemory(ctxt, "xmlSAX2Characters: huge text node"); |
| 2488 return; |
| 2489 } |
| 2490 if ((size_t)ctxt->nodelen > SIZE_T_MAX - (size_t)len || |
| 2491 (size_t)ctxt->nodemem + (size_t)len > SIZE_T_MAX / 2) { |
| 2492 xmlSAX2ErrMemory(ctxt, "xmlSAX2Characters overflow prevented"); |
| 2493 return; |
| 2494 } |
| 2448 if (ctxt->nodelen + len >= ctxt->nodemem) { | 2495 if (ctxt->nodelen + len >= ctxt->nodemem) { |
| 2449 xmlChar *newbuf; | 2496 xmlChar *newbuf; |
| 2450 » » int size; | 2497 » » size_t size; |
| 2451 | 2498 |
| 2452 size = ctxt->nodemem + len; | 2499 size = ctxt->nodemem + len; |
| 2453 size *= 2; | 2500 size *= 2; |
| 2454 newbuf = (xmlChar *) xmlRealloc(lastChild->content,size); | 2501 newbuf = (xmlChar *) xmlRealloc(lastChild->content,size); |
| 2455 if (newbuf == NULL) { | 2502 if (newbuf == NULL) { |
| 2456 xmlSAX2ErrMemory(ctxt, "xmlSAX2Characters"); | 2503 xmlSAX2ErrMemory(ctxt, "xmlSAX2Characters"); |
| 2457 return; | 2504 return; |
| 2458 } | 2505 } |
| 2459 ctxt->nodemem = size; | 2506 ctxt->nodemem = size; |
| 2460 lastChild->content = newbuf; | 2507 lastChild->content = newbuf; |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2521 | 2568 |
| 2522 if (ctx == NULL) return; | 2569 if (ctx == NULL) return; |
| 2523 parent = ctxt->node; | 2570 parent = ctxt->node; |
| 2524 #ifdef DEBUG_SAX | 2571 #ifdef DEBUG_SAX |
| 2525 xmlGenericError(xmlGenericErrorContext, | 2572 xmlGenericError(xmlGenericErrorContext, |
| 2526 "SAX.xmlSAX2ProcessingInstruction(%s, %s)\n", target, data); | 2573 "SAX.xmlSAX2ProcessingInstruction(%s, %s)\n", target, data); |
| 2527 #endif | 2574 #endif |
| 2528 | 2575 |
| 2529 ret = xmlNewDocPI(ctxt->myDoc, target, data); | 2576 ret = xmlNewDocPI(ctxt->myDoc, target, data); |
| 2530 if (ret == NULL) return; | 2577 if (ret == NULL) return; |
| 2531 parent = ctxt->node; | |
| 2532 | 2578 |
| 2533 if (ctxt->linenumbers) { | 2579 if (ctxt->linenumbers) { |
| 2534 if (ctxt->input != NULL) { | 2580 if (ctxt->input != NULL) { |
| 2535 if (ctxt->input->line < 65535) | 2581 if (ctxt->input->line < 65535) |
| 2536 ret->line = (short) ctxt->input->line; | 2582 ret->line = (short) ctxt->input->line; |
| 2537 else | 2583 else |
| 2538 ret->line = 65535; | 2584 ret->line = 65535; |
| 2539 } | 2585 } |
| 2540 } | 2586 } |
| 2541 if (ctxt->inSubset == 1) { | 2587 if (ctxt->inSubset == 1) { |
| (...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2890 */ | 2936 */ |
| 2891 void | 2937 void |
| 2892 docbDefaultSAXHandlerInit(void) | 2938 docbDefaultSAXHandlerInit(void) |
| 2893 { | 2939 { |
| 2894 xmlSAX2InitDocbDefaultSAXHandler((xmlSAXHandlerPtr) &docbDefaultSAXHandler); | 2940 xmlSAX2InitDocbDefaultSAXHandler((xmlSAXHandlerPtr) &docbDefaultSAXHandler); |
| 2895 } | 2941 } |
| 2896 | 2942 |
| 2897 #endif /* LIBXML_DOCB_ENABLED */ | 2943 #endif /* LIBXML_DOCB_ENABLED */ |
| 2898 #define bottom_SAX2 | 2944 #define bottom_SAX2 |
| 2899 #include "elfgcchack.h" | 2945 #include "elfgcchack.h" |
| OLD | NEW |