Browse code

ole2/ooxml: fixed various build issues with libjson disabled ole2: cleaned up macro usage

Kevin Lin authored on 2014/05/20 05:45:52
Showing 3 changed files
... ...
@@ -879,47 +879,46 @@ handler_enum(ole2_header_t * hdr, property_t * prop, const char *dir, cli_ctx *
879 879
     json_object *arrobj, *strmobj;
880 880
 
881 881
     name = get_property_name2(prop->name, prop->name_size);
882
-    if (ctx->options & CL_SCAN_FILE_PROPERTIES && ctx->wrkproperty != NULL) {
883
-        arrobj = json_object_object_get(ctx->wrkproperty, "Streams");
884
-        if (NULL == arrobj) {
885
-            arrobj = json_object_new_array();
882
+    if (name) {
883
+        if (ctx->options & CL_SCAN_FILE_PROPERTIES && ctx->wrkproperty != NULL) {
884
+            arrobj = json_object_object_get(ctx->wrkproperty, "Streams");
886 885
             if (NULL == arrobj) {
887
-                cli_errmsg("ole2: no memory for streams list as json array\n");
888
-                return CL_EMEM;
886
+                arrobj = json_object_new_array();
887
+                if (NULL == arrobj) {
888
+                    cli_errmsg("ole2: no memory for streams list as json array\n");
889
+                    return CL_EMEM;
890
+                }
891
+                json_object_object_add(ctx->wrkproperty, "Streams", arrobj);
889 892
             }
890
-            json_object_object_add(ctx->wrkproperty, "Streams", arrobj);
891
-        }
892
-        strmobj = json_object_new_string(name);
893
-        json_object_array_add(arrobj, strmobj);
893
+            strmobj = json_object_new_string(name);
894
+            json_object_array_add(arrobj, strmobj);
894 895
 
895
-        if (!strcmp(name, "powerpoint document")) {
896
-            cli_jsonstr(ctx->wrkproperty, "FileType", "CL_TYPE_MSPPT");
897
-        }
898
-        if (!strcmp(name, "worddocument")) {
899
-            cli_jsonstr(ctx->wrkproperty, "FileType", "CL_TYPE_MSDOC");
900
-        }
901
-        if (!strcmp(name, "workbook")) {
902
-            cli_jsonstr(ctx->wrkproperty, "FileType", "CL_TYPE_MSXLS");
896
+            if (!strcmp(name, "powerpoint document")) {
897
+                cli_jsonstr(ctx->wrkproperty, "FileType", "CL_TYPE_MSPPT");
898
+            }
899
+            if (!strcmp(name, "worddocument")) {
900
+                cli_jsonstr(ctx->wrkproperty, "FileType", "CL_TYPE_MSDOC");
901
+            }
902
+            if (!strcmp(name, "workbook")) {
903
+                cli_jsonstr(ctx->wrkproperty, "FileType", "CL_TYPE_MSXLS");
904
+            }
903 905
         }
904
-    }
905
-#endif
906 906
 
907
-    if (!hdr->has_vba) {
908
-#if HAVE_JSON
909
-#else
910
-        name = get_property_name2(prop->name, prop->name_size);
911
-#endif
912
-        if (name) {
907
+        if (!hdr->has_vba) {
913 908
             if (!strcmp(name, "_vba_project") || !strcmp(name, "powerpoint document") || !strcmp(name, "worddocument") || !strcmp(name, "_1_ole10native"))
914 909
                 hdr->has_vba = 1;
915
-#if HAVE_JSON
916
-#else
917
-            free(name);
918
-#endif
919 910
         }
911
+        free(name);
920 912
     }
921
-#if HAVE_JSON
922
-    free(name);
913
+#else
914
+        if (!hdr->has_vba) {
915
+            name = get_property_name2(prop->name, prop->name_size);
916
+            if (name) {
917
+                if (!strcmp(name, "_vba_project") || !strcmp(name, "powerpoint document") || !strcmp(name, "worddocument") || !strcmp(name, "_1_ole10native"))
918
+                    hdr->has_vba = 1;
919
+                free(name);
920
+            }
921
+        }
923 922
 #endif
924 923
 
925 924
     return CL_SUCCESS;
... ...
@@ -44,6 +44,8 @@
44 44
 #include <libxml/xmlreader.h>
45 45
 #endif
46 46
 
47
+#if HAVE_LIBXML2 && HAVE_JSON
48
+
47 49
 #define OOXML_JSON_RECLEVEL 16
48 50
 #define OOXML_JSON_RECLEVEL_MAX 5
49 51
 #define OOXML_JSON_STRLEN_MAX 100
... ...
@@ -184,8 +186,7 @@ static const char *ooxml_check_key(const char* key, size_t keylen)
184 184
 
185 185
     return NULL;
186 186
 }
187
-#if HAVE_LIBXML2
188
-#if HAVE_JSON
187
+
189 188
 static int ooxml_parse_element(xmlTextReaderPtr reader, json_object *wrkptr, int rlvl, int skip)
190 189
 {
191 190
     const char *element_tag = NULL, *end_tag = NULL;
... ...
@@ -347,14 +348,10 @@ static int ooxml_parse_document(int fd, cli_ctx *ctx)
347 347
     xmlFreeTextReader(reader);
348 348
     return ret;
349 349
 }
350
-#endif
351
-#endif
352 350
 
353 351
 static int ooxml_basic_json(int fd, cli_ctx *ctx, const char *key)
354 352
 {
355 353
     int ret = CL_SUCCESS;
356
-#if HAVE_LIBXML2
357
-#if HAVE_JSON
358 354
     const xmlChar *stack[OOXML_JSON_RECLEVEL];
359 355
     json_object *summary, *wrkptr;
360 356
     int type, rlvl = 0;
... ...
@@ -455,12 +452,6 @@ static int ooxml_basic_json(int fd, cli_ctx *ctx, const char *key)
455 455
  ooxml_basic_exit:
456 456
     xmlTextReaderClose(reader);
457 457
     xmlFreeTextReader(reader);
458
-#else
459
-    cli_dbgmsg("ooxml_basic_json: libjson needs to enabled!\n");
460
-#endif
461
-#else
462
-    cli_dbgmsg("ooxml_basic_json: libxml2 needs to enabled!\n");
463
-#endif
464 458
     return ret;
465 459
 }
466 460
 
... ...
@@ -480,7 +471,6 @@ static int ooxml_extn_cb(int fd, cli_ctx *ctx)
480 480
 
481 481
 static int ooxml_content_cb(int fd, cli_ctx *ctx)
482 482
 {
483
-#if HAVE_LIBXML2
484 483
     int ret = CL_SUCCESS;
485 484
     int core=0, extn=0, cust=0;
486 485
     const xmlChar *name, *value, *CT, *PN;
... ...
@@ -575,15 +565,12 @@ static int ooxml_content_cb(int fd, cli_ctx *ctx)
575 575
     xmlTextReaderClose(reader);
576 576
     xmlFreeTextReader(reader);
577 577
     return ret;
578
-#else
579
-    cli_dbgmsg("ooxml_content_cb: libxml2 needs to enabled!");
580
-    return CL_SUCCESS;
581
-#endif
582 578
 }
579
+#endif
583 580
 
584 581
 int cli_process_ooxml(cli_ctx *ctx)
585 582
 {
586
-#if HAVE_LIBXML2
583
+#if HAVE_LIBXML2 && HAVE_JSON
587 584
     uint32_t loff = 0;
588 585
 
589 586
     cli_dbgmsg("in cli_processooxml\n");
... ...
@@ -601,7 +588,12 @@ int cli_process_ooxml(cli_ctx *ctx)
601 601
     return unzip_single_internal(ctx, loff, ooxml_content_cb);
602 602
 #else
603 603
     cli_dbgmsg("in cli_processooxml\n");
604
+#if !HAVE_LIBXML2
604 605
     cli_dbgmsg("cli_process_ooxml: libxml2 needs to enabled!");
606
+#endif
607
+#if !HAVE_JSON
608
+    cli_dbgmsg("cli_process_ooxml: libjson needs to enabled!");
609
+#endif
605 610
     return CL_SUCCESS;
606 611
 #endif
607 612
 }
... ...
@@ -1199,8 +1199,10 @@ static int cli_vba_scandir(const char *dirname, cli_ctx *ctx, struct uniq *U)
1199 1199
     }
1200 1200
 
1201 1201
     closedir(dd);
1202
+#if HAVE_JSON
1202 1203
     if (hasmacros && ctx->options & CL_SCAN_FILE_PROPERTIES && ctx->wrkproperty != NULL)
1203 1204
         cli_jsonbool(ctx->wrkproperty, "HasMacros", 1);
1205
+#endif
1204 1206
     if(BLOCK_MACROS && hasmacros) {
1205 1207
 	cli_append_virus(ctx, "Heuristics.OLE2.ContainsMacros");
1206 1208
 	ret = CL_VIRUS;