Browse code

Adds --with-libjson-static=DIR option to configure.

The default for libjson is dynamic, but a warning will prompt users
to consider using this static option instead, with advice on how to do so.

Micah Snyder authored on 2019/10/23 06:27:45
Showing 4 changed files
... ...
@@ -11,6 +11,10 @@ ClamAV 0.101.5 is a security patch release that addresses the following issues.
11 11
   algorithm for loading signature patterns and allocating the AC trie.
12 12
   Patch courtesy of Alberto Wu.
13 13
 
14
+- Introduced a new configure option to statically link libjson-c with libclamav.
15
+  Static linking with libjson is highly recommended to prevent crashes in
16
+  applications that use libclamav alongside another JSON parsing library.
17
+
14 18
 Special thanks to the following for code contributions and bug reports:
15 19
 
16 20
 - Alberto Wu
... ...
@@ -247,7 +247,7 @@ AC_MSG_NOTICE([Summary of optional tools])
247 247
 CL_MSG_STATUS([clamdtop    ],[$CURSES_LIBS],[$enable_clamdtop])
248 248
 CL_MSG_STATUS([milter      ],[yes],[$have_milter])
249 249
 if test "X$have_curl" = "Xyes" && test "X$have_json" = "Xyes"; then
250
-    CL_MSG_STATUS([clamsubmit  ], [yes (libjson-c-dev found at $LIBJSON_HOME), libcurl-devel found at $LIBCURL_HOME)], [yes])
250
+    CL_MSG_STATUS([clamsubmit  ], [yes (libjson-c-dev found at $LIBJSON_HOME, linking=$json_linking), libcurl-devel found at $LIBCURL_HOME)], [yes])
251 251
 else
252 252
     if test "X$have_curl" != "Xyes" && test "X$have_json" != "Xyes"; then
253 253
         CL_MSG_STATUS([clamsubmit  ], [no (missing libjson-c-dev AND libcurl-devel. Use the website to submit FPs/FNs.)], [no])
... ...
@@ -284,7 +284,7 @@ CL_MSG_STATUS([bzip2       ],[$bzip_check],[$want_bzip2])
284 284
 CL_MSG_STATUS([zlib        ],[$ZLIB_HOME],[yes])
285 285
 CL_MSG_STATUS([unrar       ],[$want_unrar],[$want_unrar])
286 286
 if test "X$have_json" = "Xyes"; then
287
-    CL_MSG_STATUS([preclass    ],[yes (libjson-c-dev found at $LIBJSON_HOME)],[yes])
287
+    CL_MSG_STATUS([preclass    ],[yes (libjson-c-dev found at $LIBJSON_HOME, linking=$json_linking)],[yes])
288 288
 else
289 289
     CL_MSG_STATUS([preclass    ],[no (missing libjson-c-dev)],[no])
290 290
 fi
... ...
@@ -307,21 +307,29 @@ CL_MSG_STATUS([fts         ],[yes],[$lfs_fts_msg])
307 307
 # 4.0.x, and 4.1.0 are the known buggy versions
308 308
 # 3.4 doesn't have the bug
309 309
 if test "x$gcc_check" != "xyes"; then
310
-	AC_MSG_WARN([
310
+    AC_MSG_WARN([
311 311
 ****** Optimizations disabled to avoid compiler bugs
312 312
 ****** The resulting binaries will be slow!
313 313
 ****** It is recommended to either upgrade or downgrade your compiler
314
-])
314
+    ])
315 315
 fi
316 316
 
317 317
 if test "x$cross_compiling" != "xno" || test "x$gcc_check" != "xyes" || test "x$zlib_check" = "xno" || test "x$bzip_check" != "xok" ; then
318
-AC_MSG_WARN([
318
+    AC_MSG_WARN([
319 319
 ****** WARNING:
320 320
 ****** You are cross compiling to a different host or you are
321 321
 ****** linking to bugged system libraries or you have manually
322 322
 ****** disabled important configure checks.
323 323
 ****** Please be aware that this build may be badly broken.
324 324
 ****** DO NOT REPORT BUGS BASED ON THIS BUILD !!!
325
-])
325
+    ])
326 326
 fi
327 327
 
328
+if test "X$have_json" = "Xyes" && test "x$json_linking" = "xdynamic"; then
329
+    AC_MSG_WARN([
330
+****** libjson-c is known to share symbol names with other JSON libraries
331
+****** which may result in crashes for applications that use libclamav.
332
+****** Consider using --with-libjson-static=[path/to/libjson-c.a],
333
+****** providing a json-c library that was compiled with CFLAGS="-fPIC".
334
+    ])
335
+fi
... ...
@@ -133,7 +133,7 @@ libclamav_internal_utils_la_SOURCES=str.c\
133 133
 
134 134
 libclamav_internal_utils_la_LDFLAGS=-static @SSL_LDFLAGS@ @JSON_LDFLAGS@
135 135
 libclamav_internal_utils_la_CFLAGS=$(AM_CFLAGS)  -fPIC -DPIC @SSL_CPPFLAGS@ @JSON_CPPFLAGS@ @PCRE_CPPFLAGS@ @XML_CPPFLAGS@
136
-libclamav_internal_utils_la_LIBADD=@SSL_LIBS@ @JSON_LIBS@ @PCRE_LIBS@
136
+libclamav_internal_utils_la_LIBADD=@SSL_LIBS@ @PCRE_LIBS@
137 137
 
138 138
 libclamav_internal_utils_nothreads_la_SOURCES=str.c\
139 139
 					conv.c \
... ...
@@ -160,7 +160,7 @@ libclamav_internal_utils_nothreads_la_SOURCES=str.c\
160 160
 
161 161
 libclamav_internal_utils_nothreads_la_LDFLAGS=-static @SSL_LDFLAGS@ @JSON_LDFLAGS@
162 162
 libclamav_internal_utils_nothreads_la_CFLAGS=$(AM_CFLAGS) -DCL_NOTHREADS @SSL_CPPFLAGS@ @JSON_CPPFLAGS@ @PCRE_CPPFLAGS@
163
-libclamav_internal_utils_nothreads_la_LIBADD=@SSL_LIBS@ @JSON_LIBS@ @PCRE_LIBS@
163
+libclamav_internal_utils_nothreads_la_LIBADD=@SSL_LIBS@ @PCRE_LIBS@
164 164
 SUBDIRS=
165 165
 
166 166
 if ENABLE_LLVM
... ...
@@ -240,7 +240,7 @@ MSPACK_CFLAGS = $(LIBMSPACK_CFLAGS)
240 240
 MSPACKLIBADD = $(LIBMSPACK_LIBS)
241 241
 MSPACKDEP =
242 242
 
243
-libmspack/Makefile: 
243
+libmspack/Makefile:
244 244
 .PHONY: distdir distclean maintainer-clean
245 245
 distdir:
246 246
 	echo "make distdir requires --with-system-libmspack=no"
... ...
@@ -3,23 +3,23 @@ dnl Check for libjson
3 3
 have_json_header="no"
4 4
 AC_MSG_CHECKING([for libjson installation])
5 5
 
6
-AC_ARG_WITH([libjson],
7
-[AS_HELP_STRING([--with-libjson@<:@=DIR@:>@], [path to directory containing libjson
8
-                @<:@default=/usr/local or /usr if not found in /usr/local@:>@])],
9
-[
10
-find_json="no"
11
-if test "X$withval" = "Xyes"; then
12
-    find_json="yes"
13
-else
14
-    if test "X$withval" != "Xno"; then
15
-        if test -f "${withval}/include/json/json.h" -o -f "${withval}/include/json-c/json.h"; then
16
-            LIBJSON_HOME="$withval"
17
-            have_json_header="yes"
6
+AC_ARG_WITH([libjson], [AS_HELP_STRING([--with-libjson@<:@=DIR@:>@], [path to directory containing libjson
7
+                        @<:@default=/usr/local or /usr if not found in /usr/local@:>@])],
8
+    [
9
+        find_json="no"
10
+        if test "X$withval" = "Xyes"; then
11
+            find_json="yes"
12
+        else
13
+            if test "X$withval" != "Xno"; then
14
+                if test -f "${withval}/include/json/json.h" -o -f "${withval}/include/json-c/json.h"; then
15
+                    LIBJSON_HOME="$withval"
16
+                    have_json_header="yes"
17
+                fi
18
+            fi
18 19
         fi
19
-    fi
20
-fi
21
-],
22
-[find_json="yes"])
20
+    ],
21
+    [find_json="yes"]
22
+)
23 23
 
24 24
 if test "X$find_json" = "Xyes"; then
25 25
     for p in /usr/local /usr ; do
... ...
@@ -58,15 +58,52 @@ if test "X$have_json_header" = "Xyes"; then
58 58
         CFLAGS="$CFLAGS $JSON_CPPFLAGS"
59 59
     fi
60 60
 
61
-    AC_SEARCH_LIBS([json_object_object_get_ex], [json-c json], [
62
-        have_json="yes"
63
-        have_deprecated_json="no"], [
64
-        have_json="no"
65
-        AC_SEARCH_LIBS([json_object_object_get], [json-c json], [
61
+    AC_CHECK_LIB([json-c], [json_object_object_get_ex],
62
+        [
63
+            dnl Found
66 64
             have_json="yes"
67
-            have_deprecated_json="yes"
68
-        ])
69
-    ])
65
+            have_deprecated_json="no"
66
+            json_libname="json-c"
67
+        ],
68
+        [
69
+            dnl Not-Found
70
+            AC_CHECK_LIB([json], [json_object_object_get_ex],
71
+                [
72
+                    dnl Found
73
+                    have_json="yes"
74
+                    have_deprecated_json="no"
75
+                    json_libname="json"
76
+                ],
77
+                [
78
+                    dnl Not-Found
79
+                    AC_CHECK_LIB([json-c], [json_object_object_get],
80
+                        [
81
+                            dnl Found
82
+                            have_json="yes"
83
+                            have_deprecated_json="yes"
84
+                            json_libname="json-c"
85
+                        ],
86
+                        [
87
+                            dnl Not-Found
88
+                            AC_CHECK_LIB([json], [json_object_object_get],
89
+                                [
90
+                                    dnl Found
91
+                                    have_json="yes"
92
+                                    have_deprecated_json="yes"
93
+                                    json_libname="json"
94
+                                ],
95
+                                [
96
+                                    dnl Not-Found
97
+                                    have_json="no"
98
+                                    AC_MSG_ERROR([Unable to find libjson library.])
99
+                                ]
100
+                            )
101
+                        ]
102
+                    )
103
+                ]
104
+            )
105
+        ]
106
+    )
70 107
 
71 108
     CFLAGS="$save_CFLAGS"
72 109
     LDFLAGS="$save_LDFLAGS"
... ...
@@ -77,7 +114,19 @@ if test "X$have_json" = "Xyes"; then
77 77
     if test "X$have_deprecated_json" = "Xyes"; then
78 78
         AC_DEFINE([HAVE_DEPRECATED_JSON],1,[Define to 1 if you have a deprecated version of the 'libjson' library (-ljson).])
79 79
     fi
80
-    JSON_LIBS="$LIBS"
80
+
81
+    dnl Determine linking method to json
82
+    AC_ARG_WITH([libjson-static],
83
+        [AC_HELP_STRING([--with-libjson-static=DIR],[path to libjson-c.a static library])],
84
+        [
85
+            json_linking="static"
86
+            JSON_LIBS="$withval $LIBS"
87
+        ],
88
+        [
89
+            json_linking="dynamic"
90
+            JSON_LIBS="-l${json_libname} $LIBS"
91
+        ]
92
+    )
81 93
 fi
82 94
 
83 95
 LIBS="$save_LIBS"