Browse code

msxml: added timeout checks at various processing loops

Kevin Lin authored on 2015/03/14 02:19:20
Showing 2 changed files
... ...
@@ -216,6 +216,11 @@ static int msxml_parse_element(struct msxml_ctx *mxctx, xmlTextReaderPtr reader,
216 216
         check_state(state);
217 217
 
218 218
         while (!endtag) {
219
+#if HAVE_JSON
220
+            if (mxctx->mode && (cli_json_timeout_cycle_check(mxctx->ctx, &(mxctx->toval)) != CL_SUCCESS))
221
+                return CL_ETIMEOUT;
222
+#endif
223
+
219 224
             node_type = xmlTextReaderNodeType(reader);
220 225
             if (node_type == -1)
221 226
                 return CL_EPARSE;
... ...
@@ -366,13 +371,19 @@ int cli_msxml_parse_document(cli_ctx *ctx, xmlTextReaderPtr reader, const struct
366 366
     mxctx.keys = keys;
367 367
     mxctx.num_keys = num_keys;
368 368
 #if HAVE_JSON
369
-    if (mode)
369
+    mxctx.mode = mode;
370
+    if (mode) {
370 371
         mxctx.root = ctx->wrkproperty;
372
+        mxctx.toval = 0;
373
+    }
371 374
 #endif
372 375
 
373 376
     /* Main Processing Loop */
374 377
     while ((state = xmlTextReaderRead(reader)) == 1) {
375 378
 #if HAVE_JSON
379
+        if (mxctx.mode && (cli_json_timeout_cycle_check(mxctx.ctx, &(mxctx.toval)) != CL_SUCCESS))
380
+            return CL_ETIMEOUT;
381
+
376 382
         ret = msxml_parse_element(&mxctx, reader, 0, mxctx.root);
377 383
 #else
378 384
         ret = msxml_parse_element(&mxctx, reader, 0, NULL);
... ...
@@ -69,6 +69,7 @@ struct msxml_ctx {
69 69
 
70 70
 #if HAVE_JSON
71 71
     json_object *root;
72
+    int mode, toval;
72 73
 #endif
73 74
 };
74 75