Browse code

seek on the underlying file descriptor and not FILE*. Avoids problems on OpenBSD with cvd unpacking.

git-svn: trunk@3239

Török Edvin authored on 2007/09/23 01:00:41
Showing 2 changed files
... ...
@@ -1,3 +1,8 @@
1
+Sat Sep 22 18:14:49 EEST 2007 (edwin)
2
+-------------------------------------
3
+  * libclamav/cvd.c: seek on the underlying file descriptor and not FILE*.
4
+       Avoids problems on OpenBSD with cvd unpacking.
5
+
1 6
 Fri Sep 21 18:40:56 EEST 2007 (edwin)
2 7
 -------------------------------------
3 8
   * configure, configure.in: add comment on origin of testcases.
... ...
@@ -365,7 +365,7 @@ int cli_cvdload(FILE *fs, struct cl_engine **engine, unsigned int *signo, short
365 365
 	struct cl_cvd cvd;
366 366
 	int ret;
367 367
 	time_t s_time;
368
-
368
+	int cfd;
369 369
 
370 370
     cli_dbgmsg("in cli_cvdload()\n");
371 371
 
... ...
@@ -391,11 +391,6 @@ int cli_cvdload(FILE *fs, struct cl_engine **engine, unsigned int *signo, short
391 391
 	cli_warnmsg("***********************************************************\n");
392 392
     }
393 393
 
394
-    if(fseek(fs, 512, SEEK_SET) == -1) {
395
-	cli_errmsg("cli_cvdload(): fseek(fs, 512, SEEK_SET) failed\n");
396
-	return CL_EIO;
397
-    }
398
-
399 394
     dir = cli_gentemp(NULL);
400 395
     if(mkdir(dir, 0700)) {
401 396
 	cli_errmsg("cli_cvdload(): Can't create temporary directory %s\n", dir);
... ...
@@ -403,7 +398,20 @@ int cli_cvdload(FILE *fs, struct cl_engine **engine, unsigned int *signo, short
403 403
 	return CL_ETMPDIR;
404 404
     }
405 405
 
406
-    if(cli_untgz(fileno(fs), dir)) {
406
+    cfd = fileno(fs);
407
+
408
+    /* use only operations on file descriptors, and not on the FILE* from here on 
409
+     * if we seek the FILE*, the underlying descriptor may not seek as expected
410
+     * (for example on OpenBSD, cygwin, etc.).
411
+     * So seek the descriptor directly.
412
+     */ 
413
+
414
+    if(lseek(cfd, 512, SEEK_SET) == -1) {
415
+	cli_errmsg("cli_cvdload(): lseek(fs, 512, SEEK_SET) failed\n");
416
+	return CL_EIO;
417
+    }
418
+
419
+    if(cli_untgz(cfd, dir)) {
407 420
 	cli_errmsg("cli_cvdload(): Can't unpack CVD file.\n");
408 421
 	free(dir);
409 422
 	return CL_ECVDEXTR;