Browse code

Warn about zlib version mismatches (bb #2072).

In libclamav: if zlib version at runtime is older than at compile time, warn.
If they are the same, or newer don't warn.

clamconf warns always on mismatch.

Mismatch can happen if:
- you build zlib yourself, but as static lib and compiler picks old shared lib
(but new headers!)
- you have 2 zlibs installed, and the old one takes precedence

Libclamav doesn't warn about mismatches due to zlib upgrades since this is
normal.

Török Edvin authored on 2010/10/18 20:16:43
Showing 4 changed files
... ...
@@ -1,3 +1,7 @@
1
+Mon Oct 18 14:16:11 EEST 2010 (edwin)
2
+-------------------------------------
3
+ * clamconf/clamconf.c, libclamav/others.c: warn about zlib version mismatches (bb #2072)
4
+
1 5
 Mon Oct 18 13:55:17 EEST 2010 (edwin)
2 6
 -------------------------------------
3 7
  * libclamav/pdf.c: bb #2295
... ...
@@ -237,6 +237,8 @@ static void print_platform(struct cli_environment *env)
237 237
     }
238 238
 #endif
239 239
 
240
+    if (strcmp(ZLIB_VERSION, zlibVersion()))
241
+	printf("WARNING: zlib version mismatch: %s (%s)\n", ZLIB_VERSION, zlibVersion());
240 242
 #ifdef ZLIB_VERNUM
241 243
     printf("zlib version: %s (%s), compile flags: %02lx\n",
242 244
 	   ZLIB_VERSION, zlibVersion(), zlibCompileFlags());
... ...
@@ -1340,9 +1340,9 @@ int32_t cli_bcapi_version_compare(struct cli_bc_ctx *ctx , const uint8_t* lhs, u
1340 1340
 	if (!isdigit(lhs[i]) || !isdigit(rhs[j]))
1341 1341
 	    return lhs[i] < rhs[j] ? -1 : 1;
1342 1342
 	while (isdigit(lhs[i]) && i < lhs_len)
1343
-	    li = 10*li + (lhs[i] - '0');
1343
+	    li = 10*li + (lhs[i++] - '0');
1344 1344
 	while (isdigit(rhs[j]) && j < rhs_len)
1345
-	    ri = 10*ri + (rhs[j] - '0');
1345
+	    ri = 10*ri + (rhs[j++] - '0');
1346 1346
 	if (li < ri)
1347 1347
 	    return -1;
1348 1348
 	if (li > ri)
... ...
@@ -261,6 +261,19 @@ int cl_init(unsigned int initoptions)
261 261
 	struct timeval tv;
262 262
 	unsigned int pid = (unsigned int) getpid();
263 263
 
264
+	const char *zlibver = zlibVersion();
265
+	int cmp = cli_bcapi_version_compare(NULL, zlibver, strlen(zlibver),
266
+					    ZLIB_VERSION, strlen(ZLIB_VERSION));
267
+	if (cmp) {
268
+	    cli_dbgmsg("zlib version at runtime: %s, compile time: %s\n",
269
+		       zlibver, ZLIB_VERSION);
270
+	}
271
+	if (cmp < 0) {
272
+	    cli_warnmsg("zlib version at runtime is older than compile time: %s < %s\n",
273
+			zlibver, ZLIB_VERSION);
274
+	    cli_infomsg(NULL, "Make sure zlib is built as shared library, and that the new zlib library is installed in the proper place\n");
275
+	}
276
+
264 277
     {
265 278
 	unrar_main_header_t x;
266 279
 	if (((char*)&x.flags - (char*)&x) != 3) {