Browse code

ooxml: report hitting recursion limit to json

Kevin Lin authored on 2014/07/01 06:31:46
Showing 1 changed files
... ...
@@ -198,7 +198,7 @@ static const char *ooxml_check_key(const char* key, size_t keylen)
198 198
     return NULL;
199 199
 }
200 200
 
201
-static int ooxml_parse_element(cli_ctx *ctx, xmlTextReaderPtr reader, json_object *wrkptr, int rlvl)
201
+static int ooxml_parse_element(cli_ctx *ctx, xmlTextReaderPtr reader, json_object *wrkptr, int rlvl, json_object *root)
202 202
 {
203 203
     const char *element_tag = NULL, *end_tag = NULL;
204 204
     const xmlChar *node_name = NULL, *node_value = NULL;
... ...
@@ -213,6 +213,7 @@ static int ooxml_parse_element(cli_ctx *ctx, xmlTextReaderPtr reader, json_objec
213 213
         /* skip it */
214 214
         xmlTextReaderNext(reader);
215 215
         //return CL_EMAXREC;
216
+        cli_jsonbool(root, "HitRecursiveLimit", 1);
216 217
         return CL_SUCCESS;
217 218
     }
218 219
 
... ...
@@ -258,7 +259,10 @@ static int ooxml_parse_element(cli_ctx *ctx, xmlTextReaderPtr reader, json_objec
258 258
             }
259 259
             cli_dbgmsg("ooxml_parse_element: retrieved json object [%s]\n", element_tag);
260 260
 
261
-            ret = ooxml_parse_element(ctx, reader, thisjobj, rlvl+1);
261
+            if (rlvl == 0)
262
+                root = thisjobj;
263
+
264
+            ret = ooxml_parse_element(ctx, reader, thisjobj, rlvl+1, root);
262 265
             if (ret != CL_SUCCESS) {
263 266
                 return ret;
264 267
             }
... ...
@@ -336,7 +340,7 @@ static int ooxml_parse_document(int fd, cli_ctx *ctx)
336 336
         return CL_SUCCESS; /* libxml2 failed */
337 337
     }
338 338
 
339
-    ret = ooxml_parse_element(ctx, reader, ctx->wrkproperty, 0);
339
+    ret = ooxml_parse_element(ctx, reader, ctx->wrkproperty, 0, NULL);
340 340
 
341 341
     xmlTextReaderClose(reader);
342 342
     xmlFreeTextReader(reader);