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
... ...
@@ -9,6 +9,10 @@ ClamAV 0.102.1 is a security patch release to address the following issues.
9 9
 
10 10
 ### Bug fixes
11 11
 
12
+- Introduced a new configure option to statically link libjson-c with libclamav.
13
+  Static linking with libjson is highly recommended to prevent crashes in
14
+  applications that use libclamav alongside another JSON parsing library.
15
+
12 16
 ### Acknowledgements
13 17
 
14 18
 The ClamAV team thanks the following individuals for their code submissions:
... ...
@@ -301,7 +301,7 @@ if test "x$enable_libclamav_only" != "xyes"; then
301 301
     fi
302 302
 
303 303
     if test "X$have_json" = "Xyes"; then
304
-        CL_MSG_STATUS([clamsubmit  ], [yes (libjson-c-dev found at $LIBJSON_HOME)], [yes])
304
+        CL_MSG_STATUS([clamsubmit  ], [yes (libjson-c-dev found at $LIBJSON_HOME, linking=$json_linking)], [yes])
305 305
     else
306 306
         CL_MSG_STATUS([clamsubmit  ], [no (missing libjson-c-dev. Use the website to submit FPs/FNs.)], [no])
307 307
     fi
... ...
@@ -341,7 +341,7 @@ else
341 341
 fi
342 342
 CL_MSG_STATUS([unrar       ],[$want_unrar],[$want_unrar])
343 343
 if test "X$have_json" = "Xyes"; then
344
-    CL_MSG_STATUS([preclass    ],[yes (libjson-c-dev found at $LIBJSON_HOME)],[yes])
344
+    CL_MSG_STATUS([preclass    ],[yes (libjson-c-dev found at $LIBJSON_HOME, linking=$json_linking)],[yes])
345 345
 else
346 346
     CL_MSG_STATUS([preclass    ],[no (missing libjson-c-dev)],[no])
347 347
 fi
... ...
@@ -364,21 +364,29 @@ CL_MSG_STATUS([fts         ],[yes],[$lfs_fts_msg])
364 364
 # 4.0.x, and 4.1.0 are the known buggy versions
365 365
 # 3.4 doesn't have the bug
366 366
 if test "x$gcc_check" != "xyes"; then
367
-	AC_MSG_WARN([
367
+    AC_MSG_WARN([
368 368
 ****** Optimizations disabled to avoid compiler bugs
369 369
 ****** The resulting binaries will be slow!
370 370
 ****** It is recommended to either upgrade or downgrade your compiler
371
-])
371
+    ])
372 372
 fi
373 373
 
374 374
 if test "x$cross_compiling" != "xno" || test "x$gcc_check" != "xyes" || test "x$bzip_check" != "xok" ; then
375
-AC_MSG_WARN([
375
+    AC_MSG_WARN([
376 376
 ****** WARNING:
377 377
 ****** You are cross compiling to a different host or you are
378 378
 ****** linking to bugged system libraries or you have manually
379 379
 ****** disabled important configure checks.
380 380
 ****** Please be aware that this build may be badly broken.
381 381
 ****** DO NOT REPORT BUGS BASED ON THIS BUILD !!!
382
-])
382
+    ])
383 383
 fi
384 384
 
385
+if test "X$have_json" = "Xyes" && test "x$json_linking" = "xdynamic"; then
386
+    AC_MSG_WARN([
387
+****** libjson-c is known to share symbol names with other JSON libraries
388
+****** which may result in crashes for applications that use libclamav.
389
+****** Consider using --with-libjson-static=[path/to/libjson-c.a],
390
+****** providing a json-c library that was compiled with CFLAGS="-fPIC".
391
+    ])
392
+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
... ...
@@ -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"