Browse code

CLAM-49: throw error if using --gen-json without linking libjson-c

Kevin Lin authored on 2018/02/27 03:41:32
Showing 1 changed files
... ...
@@ -791,6 +791,19 @@ int scanmanager(const struct optstruct *opts)
791 791
         }
792 792
     }
793 793
 
794
+    /* JSON check to prevent engine loading if specified without libjson-c  */
795
+#if HAVE_JSON
796
+    if (optget(opts, "gen-json")->enabled)
797
+        options |= CL_SCAN_FILE_PROPERTIES;
798
+#else
799
+    if (optget(opts, "gen-json")->enabled) {
800
+        logg("!Can't generate json (gen-json). libjson-c dev library was missing or misconfigured when ClamAV was built.\n")
801
+
802
+        cl_engine_free(engine);
803
+        return 2;
804
+    }
805
+#endif
806
+
794 807
     if((opt = optget(opts, "tempdir"))->enabled) {
795 808
         if((ret = cl_engine_set_str(engine, CL_ENGINE_TMPDIR, opt->strarg))) {
796 809
             logg("!cli_engine_set_str(CL_ENGINE_TMPDIR) failed: %s\n", cl_strerror(ret));
... ...
@@ -1114,11 +1127,6 @@ int scanmanager(const struct optstruct *opts)
1114 1114
         procdev = sb.st_dev;
1115 1115
 #endif
1116 1116
 
1117
-#if HAVE_JSON
1118
-    if (optget(opts, "gen-json")->enabled)
1119
-        options |= CL_SCAN_FILE_PROPERTIES;
1120
-#endif
1121
-
1122 1117
     /* check filetype */
1123 1118
     if(!opts->filename && !optget(opts, "file-list")->enabled) {
1124 1119
         /* we need full path for some reasons (eg. archive handling) */