JSON: Only allow to convert PLIST_DICT or PLIST_ARRAY node to JSON
diff --git a/src/jplist.c b/src/jplist.c
index d12540e..f4adf2f 100644
--- a/src/jplist.c
+++ b/src/jplist.c
@@ -395,6 +395,11 @@
return PLIST_ERR_INVALID_ARG;
}
+ if (!PLIST_IS_DICT(plist) && !PLIST_IS_ARRAY(plist)) {
+ PLIST_JSON_WRITE_ERR("plist data is not valid for JSON format\n");
+ return PLIST_ERR_FORMAT;
+ }
+
res = node_estimate_size(plist, &size, 0, prettify);
if (res < 0) {
return res;
@@ -413,6 +418,9 @@
*length = 0;
return res;
}
+ if (prettify) {
+ str_buf_append(outbuf, "\n", 1);
+ }
str_buf_append(outbuf, "\0", 1);