1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-07-29 11:41:22 +03:00

deprecate the non-boundchecking Sprintf functions, add Snprintf this

* include/libxml/valid.h debugXML.c valid.c: deprecate
  the non-boundchecking Sprintf functions, add Snprintf
  this should close bug #57984
Daniel
This commit is contained in:
Daniel Veillard
2001-08-15 12:06:36 +00:00
parent ecb6f5bda5
commit d3d067280e
4 changed files with 95 additions and 31 deletions

View File

@ -1,3 +1,9 @@
Wed Aug 15 13:56:22 CEST 2001 Daniel Veillard <daniel@veillard.com>
* include/libxml/valid.h debugXML.c valid.c: deprecate
the non-boundchecking Sprintf functions, add Snprintf
this should close bug #57984
Wed Aug 15 10:46:07 CEST 2001 Daniel Veillard <daniel@veillard.com> Wed Aug 15 10:46:07 CEST 2001 Daniel Veillard <daniel@veillard.com>
* xmlIO.c: xmlOutputBufferCreateFilename() didn't unescaped * xmlIO.c: xmlOutputBufferCreateFilename() didn't unescaped

View File

@ -264,7 +264,7 @@ xmlDebugDumpElemDecl(FILE *output, xmlElementPtr elem, int depth) {
char buf[5001]; char buf[5001];
buf[0] = 0; buf[0] = 0;
xmlSprintfElementContent(buf, elem->content, 1); xmlSnprintfElementContent(buf, 5000, elem->content, 1);
buf[5000] = 0; buf[5000] = 0;
fprintf(output, "%s", buf); fprintf(output, "%s", buf);
} }

View File

@ -116,9 +116,15 @@ xmlElementContentPtr xmlNewElementContent (xmlChar *name,
xmlElementContentType type); xmlElementContentType type);
xmlElementContentPtr xmlCopyElementContent(xmlElementContentPtr content); xmlElementContentPtr xmlCopyElementContent(xmlElementContentPtr content);
void xmlFreeElementContent(xmlElementContentPtr cur); void xmlFreeElementContent(xmlElementContentPtr cur);
void xmlSnprintfElementContent(char *buf,
int size,
xmlElementContentPtr content,
int glob);
/* DEPRECATED */
void xmlSprintfElementContent(char *buf, void xmlSprintfElementContent(char *buf,
xmlElementContentPtr content, xmlElementContentPtr content,
int glob); int glob);
/* DEPRECATED */
/* Element */ /* Element */
xmlElementPtr xmlAddElementDecl (xmlValidCtxtPtr ctxt, xmlElementPtr xmlAddElementDecl (xmlValidCtxtPtr ctxt,

112
valid.c
View File

@ -240,7 +240,7 @@ xmlValidDebug(xmlNodePtr cur, xmlElementContentPtr cont) {
xmlGenericError(xmlGenericErrorContext, "valid: "); xmlGenericError(xmlGenericErrorContext, "valid: ");
xmlValidPrintNodeList(cur); xmlValidPrintNodeList(cur);
xmlGenericError(xmlGenericErrorContext, "against "); xmlGenericError(xmlGenericErrorContext, "against ");
xmlSprintfElementContent(expr, cont, 1); xmlSnprintfElementContent(expr, 5000, cont, 1);
xmlGenericError(xmlGenericErrorContext, "%s\n", expr); xmlGenericError(xmlGenericErrorContext, "%s\n", expr);
} }
@ -551,43 +551,82 @@ xmlDumpElementContent(xmlBufferPtr buf, xmlElementContentPtr content, int glob)
* @content: An element table * @content: An element table
* @glob: 1 if one must print the englobing parenthesis, 0 otherwise * @glob: 1 if one must print the englobing parenthesis, 0 otherwise
* *
* Deprecated, unsafe, use xmlSnprintfElementContent
*/
void
xmlSprintfElementContent(char *buf ATTRIBUTE_UNUSED,
xmlElementContentPtr content ATTRIBUTE_UNUSED,
int glob ATTRIBUTE_UNUSED) {
}
/**
* xmlSnprintfElementContent:
* @buf: an output buffer
* @size: the buffer size
* @content: An element table
* @glob: 1 if one must print the englobing parenthesis, 0 otherwise
*
* This will dump the content of the element content definition * This will dump the content of the element content definition
* Intended just for the debug routine * Intended just for the debug routine
*/ */
void void
xmlSprintfElementContent(char *buf, xmlElementContentPtr content, int glob) { xmlSnprintfElementContent(char *buf, int size, xmlElementContentPtr content, int glob) {
int len;
if (content == NULL) return; if (content == NULL) return;
len = strlen(buf);
if (size - len < 50) {
if ((size - len > 4) && (buf[len - 1] != '.'))
strcat(buf, " ...");
return;
}
if (glob) strcat(buf, "("); if (glob) strcat(buf, "(");
switch (content->type) { switch (content->type) {
case XML_ELEMENT_CONTENT_PCDATA: case XML_ELEMENT_CONTENT_PCDATA:
strcat(buf, "#PCDATA"); strcat(buf, "#PCDATA");
break; break;
case XML_ELEMENT_CONTENT_ELEMENT: case XML_ELEMENT_CONTENT_ELEMENT:
if (size - len < xmlStrlen(content->name + 10)) {
strcat(buf, " ...");
return;
}
strcat(buf, (char *) content->name); strcat(buf, (char *) content->name);
break; break;
case XML_ELEMENT_CONTENT_SEQ: case XML_ELEMENT_CONTENT_SEQ:
if ((content->c1->type == XML_ELEMENT_CONTENT_OR) || if ((content->c1->type == XML_ELEMENT_CONTENT_OR) ||
(content->c1->type == XML_ELEMENT_CONTENT_SEQ)) (content->c1->type == XML_ELEMENT_CONTENT_SEQ))
xmlSprintfElementContent(buf, content->c1, 1); xmlSnprintfElementContent(buf, size, content->c1, 1);
else else
xmlSprintfElementContent(buf, content->c1, 0); xmlSnprintfElementContent(buf, size, content->c1, 0);
len = strlen(buf);
if (size - len < 50) {
if ((size - len > 4) && (buf[len - 1] != '.'))
strcat(buf, " ...");
return;
}
strcat(buf, " , "); strcat(buf, " , ");
if (content->c2->type == XML_ELEMENT_CONTENT_OR) if (content->c2->type == XML_ELEMENT_CONTENT_OR)
xmlSprintfElementContent(buf, content->c2, 1); xmlSnprintfElementContent(buf, size, content->c2, 1);
else else
xmlSprintfElementContent(buf, content->c2, 0); xmlSnprintfElementContent(buf, size, content->c2, 0);
break; break;
case XML_ELEMENT_CONTENT_OR: case XML_ELEMENT_CONTENT_OR:
if ((content->c1->type == XML_ELEMENT_CONTENT_OR) || if ((content->c1->type == XML_ELEMENT_CONTENT_OR) ||
(content->c1->type == XML_ELEMENT_CONTENT_SEQ)) (content->c1->type == XML_ELEMENT_CONTENT_SEQ))
xmlSprintfElementContent(buf, content->c1, 1); xmlSnprintfElementContent(buf, size, content->c1, 1);
else else
xmlSprintfElementContent(buf, content->c1, 0); xmlSnprintfElementContent(buf, size, content->c1, 0);
len = strlen(buf);
if (size - len < 50) {
if ((size - len > 4) && (buf[len - 1] != '.'))
strcat(buf, " ...");
return;
}
strcat(buf, " | "); strcat(buf, " | ");
if (content->c2->type == XML_ELEMENT_CONTENT_SEQ) if (content->c2->type == XML_ELEMENT_CONTENT_SEQ)
xmlSprintfElementContent(buf, content->c2, 1); xmlSnprintfElementContent(buf, size, content->c2, 1);
else else
xmlSprintfElementContent(buf, content->c2, 0); xmlSnprintfElementContent(buf, size, content->c2, 0);
break; break;
} }
if (glob) if (glob)
@ -3634,8 +3673,9 @@ analyze:
} }
/** /**
* xmlSprintfElements: * xmlSnprintfElements:
* @buf: an output buffer * @buf: an output buffer
* @size: the size of the buffer
* @content: An element * @content: An element
* @glob: 1 if one must print the englobing parenthesis, 0 otherwise * @glob: 1 if one must print the englobing parenthesis, 0 otherwise
* *
@ -3643,28 +3683,40 @@ analyze:
* Intended just for the debug routine * Intended just for the debug routine
*/ */
static void static void
xmlSprintfElements(char *buf, xmlNodePtr node, int glob) { xmlSnprintfElements(char *buf, int size, xmlNodePtr node, int glob) {
xmlNodePtr cur; xmlNodePtr cur;
int len;
if (node == NULL) return; if (node == NULL) return;
if (glob) strcat(buf, "("); if (glob) strcat(buf, "(");
cur = node; cur = node;
while (cur != NULL) { while (cur != NULL) {
len = strlen(buf);
if (size - len < 50) {
if ((size - len > 4) && (buf[len - 1] != '.'))
strcat(buf, " ...");
return;
}
switch (cur->type) { switch (cur->type) {
case XML_ELEMENT_NODE: case XML_ELEMENT_NODE:
strcat(buf, (char *) cur->name); if (size - len < xmlStrlen(cur->name + 10)) {
if (cur->next != NULL) if ((size - len > 4) && (buf[len - 1] != '.'))
strcat(buf, " "); strcat(buf, " ...");
break; return;
}
strcat(buf, (char *) cur->name);
if (cur->next != NULL)
strcat(buf, " ");
break;
case XML_TEXT_NODE: case XML_TEXT_NODE:
if (xmlIsBlankNode(cur)) if (xmlIsBlankNode(cur))
break; break;
case XML_CDATA_SECTION_NODE: case XML_CDATA_SECTION_NODE:
case XML_ENTITY_REF_NODE: case XML_ENTITY_REF_NODE:
strcat(buf, "CDATA"); strcat(buf, "CDATA");
if (cur->next != NULL) if (cur->next != NULL)
strcat(buf, " "); strcat(buf, " ");
break; break;
case XML_ATTRIBUTE_NODE: case XML_ATTRIBUTE_NODE:
case XML_DOCUMENT_NODE: case XML_DOCUMENT_NODE:
#ifdef LIBXML_DOCB_ENABLED #ifdef LIBXML_DOCB_ENABLED
@ -3675,10 +3727,10 @@ xmlSprintfElements(char *buf, xmlNodePtr node, int glob) {
case XML_DOCUMENT_FRAG_NODE: case XML_DOCUMENT_FRAG_NODE:
case XML_NOTATION_NODE: case XML_NOTATION_NODE:
case XML_NAMESPACE_DECL: case XML_NAMESPACE_DECL:
strcat(buf, "???"); strcat(buf, "???");
if (cur->next != NULL) if (cur->next != NULL)
strcat(buf, " "); strcat(buf, " ");
break; break;
case XML_ENTITY_NODE: case XML_ENTITY_NODE:
case XML_PI_NODE: case XML_PI_NODE:
case XML_DTD_NODE: case XML_DTD_NODE:
@ -3688,7 +3740,7 @@ xmlSprintfElements(char *buf, xmlNodePtr node, int glob) {
case XML_ENTITY_DECL: case XML_ENTITY_DECL:
case XML_XINCLUDE_START: case XML_XINCLUDE_START:
case XML_XINCLUDE_END: case XML_XINCLUDE_END:
break; break;
} }
cur = cur->next; cur = cur->next;
} }
@ -3824,12 +3876,12 @@ xmlValidateElementContent(xmlValidCtxtPtr ctxt, xmlNodePtr child,
char list[5000]; char list[5000];
expr[0] = 0; expr[0] = 0;
xmlSprintfElementContent(expr, cont, 1); xmlSnprintfElementContent(expr, 5000, cont, 1);
list[0] = 0; list[0] = 0;
if (repl != NULL) if (repl != NULL)
xmlSprintfElements(list, repl, 1); xmlSnprintfElements(list, 5000, repl, 1);
else else
xmlSprintfElements(list, child, 1); xmlSnprintfElements(list, 5000, child, 1);
if (name != NULL) { if (name != NULL) {
VERROR(ctxt->userData, VERROR(ctxt->userData,