Browse code

make sure fd is properly lseek'ed

git-svn: trunk@2028

Tomasz Kojm authored on 2006/06/16 18:21:02
Showing 2 changed files
... ...
@@ -1,3 +1,8 @@
1
+Fri Jun 16 11:16:35 CEST 2006 (tk)
2
+----------------------------------
3
+  * libclamav/cvd.c: cli_cvdload: make sure fd is properly lseek'ed
4
+		     Thanks to Richard Birkett <richard*musicbox.net>
5
+
1 6
 Thu Jun 15 15:55:08 CEST 2006 (tk)
2 7
 ----------------------------------
3 8
   * sigtool/sigtool.c: new option --run-cdiff
... ...
@@ -29,6 +29,7 @@
29 29
 #include <sys/types.h>
30 30
 #include <sys/stat.h>
31 31
 #include <fcntl.h>
32
+#include <unistd.h>
32 33
 #include <zlib.h>
33 34
 #include <time.h>
34 35
 
... ...
@@ -341,7 +342,7 @@ int cli_cvdload(FILE *fs, struct cl_engine **engine, unsigned int *signo, short
341 341
 {
342 342
         char *dir;
343 343
 	struct cl_cvd cvd;
344
-	int ret;
344
+	int ret, fd;
345 345
 	time_t stime;
346 346
 
347 347
 
... ...
@@ -369,16 +370,26 @@ int cli_cvdload(FILE *fs, struct cl_engine **engine, unsigned int *signo, short
369 369
 	cli_warnmsg("********************************************************\n");
370 370
     }
371 371
 
372
-    fseek(fs, 512, SEEK_SET);
372
+    if((fd = dup(fileno(fs))) == -1) {
373
+	cli_errmsg("cli_cvdload(): Can't duplicate descriptor %d\n", fileno(fs));
374
+	return CL_EIO;
375
+    }
376
+
377
+    if(lseek(fd, 512, SEEK_SET) == -1) {
378
+	cli_errmsg("cli_cvdload(): Can't lseek descriptor %d\n", fd);
379
+	close(fd);
380
+	return CL_EIO;
381
+    }
373 382
 
374 383
     dir = cli_gentemp(NULL);
375 384
     if(mkdir(dir, 0700)) {
376
-	cli_errmsg("cli_cvdload():  Can't create temporary directory %s\n", dir);
385
+	cli_errmsg("cli_cvdload(): Can't create temporary directory %s\n", dir);
377 386
 	free(dir);
387
+	close(fd);
378 388
 	return CL_ETMPDIR;
379 389
     }
380 390
 
381
-    if(cli_untgz(dup(fileno(fs)), dir)) {
391
+    if(cli_untgz(fd, dir)) {
382 392
 	cli_errmsg("cli_cvdload(): Can't unpack CVD file.\n");
383 393
 	free(dir);
384 394
 	return CL_ECVDEXTR;