From 2782c743152d812da909fd1950f28c96aed57d0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?T=C3=B6r=C3=B6k=20Edvin?= Date: Sat, 22 Sep 2007 16:00:41 +0000 Subject: [PATCH] seek on the underlying file descriptor and not FILE*. Avoids problems on OpenBSD with cvd unpacking. git-svn: trunk@3239 --- ChangeLog | 5 +++++ libclamav/cvd.c | 22 +++++++++++++++------- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index 656236541..72d9bdb56 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Sat Sep 22 18:14:49 EEST 2007 (edwin) +------------------------------------- + * libclamav/cvd.c: seek on the underlying file descriptor and not FILE*. + Avoids problems on OpenBSD with cvd unpacking. + Fri Sep 21 18:40:56 EEST 2007 (edwin) ------------------------------------- * configure, configure.in: add comment on origin of testcases. diff --git a/libclamav/cvd.c b/libclamav/cvd.c index 8dc7dee4b..29886b7eb 100644 --- a/libclamav/cvd.c +++ b/libclamav/cvd.c @@ -365,7 +365,7 @@ int cli_cvdload(FILE *fs, struct cl_engine **engine, unsigned int *signo, short struct cl_cvd cvd; int ret; time_t s_time; - + int cfd; cli_dbgmsg("in cli_cvdload()\n"); @@ -391,11 +391,6 @@ int cli_cvdload(FILE *fs, struct cl_engine **engine, unsigned int *signo, short cli_warnmsg("***********************************************************\n"); } - if(fseek(fs, 512, SEEK_SET) == -1) { - cli_errmsg("cli_cvdload(): fseek(fs, 512, SEEK_SET) failed\n"); - return CL_EIO; - } - dir = cli_gentemp(NULL); if(mkdir(dir, 0700)) { 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 return CL_ETMPDIR; } - if(cli_untgz(fileno(fs), dir)) { + cfd = fileno(fs); + + /* use only operations on file descriptors, and not on the FILE* from here on + * if we seek the FILE*, the underlying descriptor may not seek as expected + * (for example on OpenBSD, cygwin, etc.). + * So seek the descriptor directly. + */ + + if(lseek(cfd, 512, SEEK_SET) == -1) { + cli_errmsg("cli_cvdload(): lseek(fs, 512, SEEK_SET) failed\n"); + return CL_EIO; + } + + if(cli_untgz(cfd, dir)) { cli_errmsg("cli_cvdload(): Can't unpack CVD file.\n"); free(dir); return CL_ECVDEXTR;