aboutsummaryrefslogtreecommitdiff
path: root/tools/gator/daemon/mxml/mxml-file.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/gator/daemon/mxml/mxml-file.c')
-rw-r--r--tools/gator/daemon/mxml/mxml-file.c104
1 files changed, 39 insertions, 65 deletions
diff --git a/tools/gator/daemon/mxml/mxml-file.c b/tools/gator/daemon/mxml/mxml-file.c
index 7860ee5f8370..3812c253fc3e 100644
--- a/tools/gator/daemon/mxml/mxml-file.c
+++ b/tools/gator/daemon/mxml/mxml-file.c
@@ -1,9 +1,9 @@
/*
- * "$Id: mxml-file.c 438 2011-03-24 05:47:51Z mike $"
+ * "$Id: mxml-file.c 455 2014-01-05 03:28:03Z msweet $"
*
* File loading code for Mini-XML, a small XML-like file parsing library.
*
- * Copyright 2003-2011 by Michael R Sweet.
+ * Copyright 2003-2014 by Michael R Sweet.
*
* These coded instructions, statements, and computer programs are the
* property of Michael R Sweet and are protected by Federal copyright
@@ -11,44 +11,11 @@
* which should have been included with this file. If this file is
* missing or damaged, see the license at:
*
- * http://www.minixml.org/
- *
- * Contents:
- *
- * mxmlLoadFd() - Load a file descriptor into an XML node tree.
- * mxmlLoadFile() - Load a file into an XML node tree.
- * mxmlLoadString() - Load a string into an XML node tree.
- * mxmlSaveAllocString() - Save an XML tree to an allocated string.
- * mxmlSaveFd() - Save an XML tree to a file descriptor.
- * mxmlSaveFile() - Save an XML tree to a file.
- * mxmlSaveString() - Save an XML node tree to a string.
- * mxmlSAXLoadFd() - Load a file descriptor into an XML node tree
- * using a SAX callback.
- * mxmlSAXLoadFile() - Load a file into an XML node tree
- * using a SAX callback.
- * mxmlSAXLoadString() - Load a string into an XML node tree
- * using a SAX callback.
- * mxmlSetCustomHandlers() - Set the handling functions for custom data.
- * mxmlSetErrorCallback() - Set the error message callback.
- * mxmlSetWrapMargin() - Set the wrap margin when saving XML data.
- * mxml_add_char() - Add a character to a buffer, expanding as needed.
- * mxml_fd_getc() - Read a character from a file descriptor.
- * mxml_fd_putc() - Write a character to a file descriptor.
- * mxml_fd_read() - Read a buffer of data from a file descriptor.
- * mxml_fd_write() - Write a buffer of data to a file descriptor.
- * mxml_file_getc() - Get a character from a file.
- * mxml_file_putc() - Write a character to a file.
- * mxml_get_entity() - Get the character corresponding to an entity...
- * mxml_load_data() - Load data into an XML node tree.
- * mxml_parse_element() - Parse an element for any attributes...
- * mxml_string_getc() - Get a character from a string.
- * mxml_string_putc() - Write a character to a string.
- * mxml_write_name() - Write a name string.
- * mxml_write_node() - Save an XML node to a file.
- * mxml_write_string() - Write a string, escaping & and < as needed.
- * mxml_write_ws() - Do whitespace callback...
+ * http://www.msweet.org/projects.php/Mini-XML
*/
+/*** This file modified by ARM on 25 Aug 2014 to avoid pointer overflow when checking if the write position is beyond the end of the buffer in mxmlSaveString and mxml_string_putc ***/
+
/*
* Include necessary headers...
*/
@@ -128,7 +95,7 @@ static int mxml_write_node(mxml_node_t *node, void *p,
_mxml_global_t *global);
static int mxml_write_string(const char *s, void *p,
_mxml_putc_cb_t putc_cb);
-static int mxml_write_ws(mxml_node_t *node, void *p,
+static int mxml_write_ws(mxml_node_t *node, void *p,
mxml_save_cb_t cb, int ws,
int col, _mxml_putc_cb_t putc_cb);
@@ -400,7 +367,7 @@ mxmlSaveString(mxml_node_t *node, /* I - Node to write */
mxml_save_cb_t cb) /* I - Whitespace callback or MXML_NO_CALLBACK */
{
int col; /* Final column */
- char *ptr[2]; /* Pointers for putc_cb */
+ char *ptr[3]; /* Pointers for putc_cb */
_mxml_global_t *global = _mxml_global();
/* Global data */
@@ -411,6 +378,7 @@ mxmlSaveString(mxml_node_t *node, /* I - Node to write */
ptr[0] = buffer;
ptr[1] = buffer + bufsize;
+ ptr[2] = 0;
if ((col = mxml_write_node(node, ptr, cb, 0, mxml_string_putc, global)) < 0)
return (-1);
@@ -422,7 +390,7 @@ mxmlSaveString(mxml_node_t *node, /* I - Node to write */
* Nul-terminate the buffer...
*/
- if (ptr[0] >= ptr[1])
+ if (ptr[2] != 0)
buffer[bufsize - 1] = '\0';
else
ptr[0][0] = '\0';
@@ -567,7 +535,7 @@ mxmlSAXLoadString(
*
* The save function accepts a node pointer and must return a malloc'd
* string on success and NULL on error.
- *
+ *
*/
void
@@ -756,7 +724,7 @@ mxml_fd_getc(void *p, /* I - File descriptor buffer */
return (EOF);
ch = *(buf->current)++;
-
+
if (ch != 0xff)
return (EOF);
@@ -775,7 +743,7 @@ mxml_fd_getc(void *p, /* I - File descriptor buffer */
return (EOF);
ch = *(buf->current)++;
-
+
if (ch != 0xfe)
return (EOF);
@@ -1287,8 +1255,8 @@ mxml_file_getc(void *p, /* I - Pointer to file */
* Multi-word UTF-16 char...
*/
- int lch = (getc(fp) << 8);
- lch |= getc(fp);
+ int lch = getc(fp);
+ lch = (lch << 8) | getc(fp);
if (lch < 0xdc00 || lch >= 0xdfff)
return (EOF);
@@ -1317,7 +1285,7 @@ mxml_file_getc(void *p, /* I - Pointer to file */
*/
int lch = getc(fp);
- lch |= (getc(fp) << 8);
+ lch |= (getc(fp) << 8);
if (lch < 0xdc00 || lch >= 0xdfff)
return (EOF);
@@ -1463,8 +1431,10 @@ mxml_load_data(
if (cb && parent)
type = (*cb)(parent);
- else
+ else if (parent)
type = MXML_TEXT;
+ else
+ type = MXML_IGNORE;
while ((ch = (*getc_cb)(p, &encoding)) != EOF)
{
@@ -1518,7 +1488,7 @@ mxml_load_data(
default : /* Ignore... */
node = NULL;
break;
- }
+ }
if (*bufptr)
{
@@ -1661,9 +1631,9 @@ mxml_load_data(
* There can only be one root element!
*/
- mxml_error("<%s> cannot be a second root node after <%s>",
+ mxml_error("<%s> cannot be a second root node after <%s>",
buffer, first->value.element.name);
- goto error;
+ goto error;
}
if ((node = mxmlNewElement(parent, buffer)) == NULL)
@@ -1729,9 +1699,9 @@ mxml_load_data(
* There can only be one root element!
*/
- mxml_error("<%s> cannot be a second root node after <%s>",
+ mxml_error("<%s> cannot be a second root node after <%s>",
buffer, first->value.element.name);
- goto error;
+ goto error;
}
if ((node = mxmlNewElement(parent, buffer)) == NULL)
@@ -1796,9 +1766,9 @@ mxml_load_data(
* There can only be one root element!
*/
- mxml_error("<%s> cannot be a second root node after <%s>",
+ mxml_error("<%s> cannot be a second root node after <%s>",
buffer, first->value.element.name);
- goto error;
+ goto error;
}
if ((node = mxmlNewElement(parent, buffer)) == NULL)
@@ -1882,9 +1852,9 @@ mxml_load_data(
* There can only be one root element!
*/
- mxml_error("<%s> cannot be a second root node after <%s>",
+ mxml_error("<%s> cannot be a second root node after <%s>",
buffer, first->value.element.name);
- goto error;
+ goto error;
}
if ((node = mxmlNewElement(parent, buffer)) == NULL)
@@ -1974,9 +1944,9 @@ mxml_load_data(
* There can only be one root element!
*/
- mxml_error("<%s> cannot be a second root node after <%s>",
+ mxml_error("<%s> cannot be a second root node after <%s>",
buffer, first->value.element.name);
- goto error;
+ goto error;
}
if ((node = mxmlNewElement(parent, buffer)) == NULL)
@@ -2076,7 +2046,7 @@ mxml_load_data(
{
node = parent;
- while (parent->parent != top && parent->parent)
+ while (parent != top && parent->parent)
parent = parent->parent;
if (node != parent)
@@ -2286,7 +2256,7 @@ mxml_parse_element(
if (ch == '&')
if ((ch = mxml_get_entity(node, p, encoding, getc_cb)) == EOF)
goto error;
-
+
if (mxml_add_char(ch, &ptr, &value, &valsize))
goto error;
}
@@ -2310,7 +2280,7 @@ mxml_parse_element(
if (ch == '&')
if ((ch = mxml_get_entity(node, p, encoding, getc_cb)) == EOF)
goto error;
-
+
if (mxml_add_char(ch, &ptr, &value, &valsize))
goto error;
}
@@ -2643,8 +2613,12 @@ mxml_string_putc(int ch, /* I - Character to write */
pp = (char **)p;
- if (pp[0] < pp[1])
- pp[0][0] = ch;
+ if (pp[2] == 0) {
+ if (pp[0] < pp[1])
+ pp[0][0] = ch;
+ else
+ pp[2] = (char *)1;
+ }
pp[0] ++;
@@ -3078,5 +3052,5 @@ mxml_write_ws(mxml_node_t *node, /* I - Current node */
/*
- * End of "$Id: mxml-file.c 438 2011-03-24 05:47:51Z mike $".
+ * End of "$Id: mxml-file.c 455 2014-01-05 03:28:03Z msweet $".
*/