summaryrefslogtreecommitdiffstats
path: root/src/xplist.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/xplist.c')
-rw-r--r--src/xplist.c24
1 files changed, 19 insertions, 5 deletions
diff --git a/src/xplist.c b/src/xplist.c
index c45a984..94006f1 100644
--- a/src/xplist.c
+++ b/src/xplist.c
@@ -81,8 +81,10 @@ static const char XML_PLIST_EPILOG[] = "</plist>\n";
81#ifdef DEBUG 81#ifdef DEBUG
82static int plist_xml_debug = 0; 82static int plist_xml_debug = 0;
83#define PLIST_XML_ERR(...) if (plist_xml_debug) { fprintf(stderr, "libplist[xmlparser] ERROR: " __VA_ARGS__); } 83#define PLIST_XML_ERR(...) if (plist_xml_debug) { fprintf(stderr, "libplist[xmlparser] ERROR: " __VA_ARGS__); }
84#define PLIST_XML_WRITE_ERR(...) if (plist_xml_debug) { fprintf(stderr, "libplist[xmlwriter] ERROR: " __VA_ARGS__); }
84#else 85#else
85#define PLIST_XML_ERR(...) 86#define PLIST_XML_ERR(...)
87#define PLIST_XML_WRITE_ERR(...)
86#endif 88#endif
87 89
88void plist_xml_init(void) 90void plist_xml_init(void)
@@ -125,7 +127,7 @@ static size_t dtostr(char *buf, size_t bufsize, double realval)
125 return len; 127 return len;
126} 128}
127 129
128static void node_to_xml(node_t* node, bytearray_t **outbuf, uint32_t depth) 130static int node_to_xml(node_t* node, bytearray_t **outbuf, uint32_t depth)
129{ 131{
130 plist_data_t node_data = NULL; 132 plist_data_t node_data = NULL;
131 133
@@ -139,8 +141,10 @@ static void node_to_xml(node_t* node, bytearray_t **outbuf, uint32_t depth)
139 141
140 uint32_t i = 0; 142 uint32_t i = 0;
141 143
142 if (!node) 144 if (!node) {
143 return; 145 PLIST_XML_WRITE_ERR("Encountered invalid empty node in property list\n");
146 return -1;
147 }
144 148
145 node_data = plist_get_data(node); 149 node_data = plist_get_data(node);
146 150
@@ -232,6 +236,9 @@ static void node_to_xml(node_t* node, bytearray_t **outbuf, uint32_t depth)
232 val_len = snprintf(val, 64, "%"PRIi64, node_data->intval); 236 val_len = snprintf(val, 64, "%"PRIi64, node_data->intval);
233 } 237 }
234 break; 238 break;
239 case PLIST_NULL:
240 PLIST_XML_WRITE_ERR("PLIST_NULL type is not valid for XML format\n");
241 return -1;
235 default: 242 default:
236 break; 243 break;
237 } 244 }
@@ -353,7 +360,8 @@ static void node_to_xml(node_t* node, bytearray_t **outbuf, uint32_t depth)
353 } 360 }
354 node_t *ch; 361 node_t *ch;
355 for (ch = node_first_child(node); ch; ch = node_next_sibling(ch)) { 362 for (ch = node_first_child(node); ch; ch = node_next_sibling(ch)) {
356 node_to_xml(ch, outbuf, depth+1); 363 int res = node_to_xml(ch, outbuf, depth+1);
364 if (res < 0) return res;
357 } 365 }
358 366
359 /* fix indent for structured types */ 367 /* fix indent for structured types */
@@ -369,6 +377,7 @@ static void node_to_xml(node_t* node, bytearray_t **outbuf, uint32_t depth)
369 str_buf_append(*outbuf, ">", 1); 377 str_buf_append(*outbuf, ">", 1);
370 } 378 }
371 str_buf_append(*outbuf, "\n", 1); 379 str_buf_append(*outbuf, "\n", 1);
380 return 0;
372} 381}
373 382
374static void parse_date(const char *strval, struct TM *btime) 383static void parse_date(const char *strval, struct TM *btime)
@@ -519,7 +528,12 @@ PLIST_API void plist_to_xml(plist_t plist, char **plist_xml, uint32_t * length)
519 528
520 str_buf_append(outbuf, XML_PLIST_PROLOG, sizeof(XML_PLIST_PROLOG)-1); 529 str_buf_append(outbuf, XML_PLIST_PROLOG, sizeof(XML_PLIST_PROLOG)-1);
521 530
522 node_to_xml(plist, &outbuf, 0); 531 if (node_to_xml(plist, &outbuf, 0) < 0) {
532 str_buf_free(outbuf);
533 *plist_xml = NULL;
534 *length = 0;
535 return;
536 }
523 537
524 str_buf_append(outbuf, XML_PLIST_EPILOG, sizeof(XML_PLIST_EPILOG)); 538 str_buf_append(outbuf, XML_PLIST_EPILOG, sizeof(XML_PLIST_EPILOG));
525 539