improve generating of temporary file names

git-svn: trunk@1101
remotes/push_mirror/metadata
Tomasz Kojm 21 years ago
parent 3755dd3f2e
commit 0c7019c585
  1. 5
      clamav-devel/ChangeLog
  2. 14
      clamav-devel/libclamav/cvd.c
  3. 13
      clamav-devel/libclamav/others.c
  4. 111
      clamav-devel/libclamav/scanners.c
  5. 14
      clamav-devel/libclamav/vba_extract.c

@ -1,3 +1,8 @@
Tue Nov 16 18:07:39 CET 2004 (tk)
---------------------------------
* libclamav: improve generating of temporary file names (as requested by
Boguslaw Brandys and Nigel)
Tue Nov 16 16:58:12 CET 2004 (tk)
---------------------------------
* freshclam/manager.c: get_database: terminate buffer after recv() call

@ -333,7 +333,6 @@ int cli_cvdload(FILE *fd, struct cl_node **root, unsigned int *signo, short warn
char *dir, *tmp, *buffer;
struct cl_cvd cvd;
int bytes, ret;
const char *tmpdir;
FILE *tmpd;
time_t stime;
@ -364,16 +363,7 @@ int cli_cvdload(FILE *fd, struct cl_node **root, unsigned int *signo, short warn
fseek(fd, 512, SEEK_SET);
tmpdir = getenv("TMPDIR");
if(tmpdir == NULL)
#ifdef P_tmpdir
tmpdir = P_tmpdir;
#else
tmpdir = "/tmp";
#endif
dir = cli_gentemp(tmpdir);
dir = cli_gentemp(NULL);
if(mkdir(dir, 0700)) {
cli_errmsg("cli_cvdload(): Can't create temporary directory %s\n", dir);
return CL_ETMPDIR;
@ -392,7 +382,7 @@ int cli_cvdload(FILE *fd, struct cl_node **root, unsigned int *signo, short warn
/* start */
tmp = cli_gentemp(tmpdir);
tmp = cli_gentemp(NULL);
if((tmpd = fopen(tmp, "wb+")) == NULL) {
cli_errmsg("Can't create temporary file %s\n", tmp);
free(dir);

@ -352,10 +352,15 @@ char *cli_gentemp(const char *dir)
struct stat foo;
if(!dir)
mdir = "/tmp";
else
mdir = (char *) dir;
if(!dir) {
if((mdir = getenv("TMPDIR")) == NULL)
#ifdef P_tmpdir
mdir = P_tmpdir;
#else
mdir = "/tmp";
#endif
} else
mdir = dir;
name = (char*) cli_calloc(strlen(mdir) + 1 + 16 + 1 + 7, sizeof(char));
if(name == NULL) {

@ -656,7 +656,6 @@ static int cli_scanmscab(int desc, const char **virname, long int *scanned, cons
struct mscab_decompressor *cabd = NULL;
struct mscabd_cabinet *base, *cab;
struct mscabd_file *file;
const char *tmpdir;
char *tempname;
int ret = CL_CLEAN;
@ -674,13 +673,6 @@ static int cli_scanmscab(int desc, const char **virname, long int *scanned, cons
return CL_EMSCAB;
}
if((tmpdir = getenv("TMPDIR")) == NULL)
#ifdef P_tmpdir
tmpdir = P_tmpdir;
#else
tmpdir = "/tmp";
#endif
for(cab = base; cab; cab = cab->next) {
for(file = cab->files; file; file = file->next) {
@ -695,7 +687,7 @@ static int cli_scanmscab(int desc, const char **virname, long int *scanned, cons
continue;
}
tempname = cli_gentemp(tmpdir);
tempname = cli_gentemp(NULL);
cli_dbgmsg("MSCAB: Extracting data to %s\n", tempname);
if(cabd->extract(cabd, file, tempname)) {
cli_dbgmsg("MSCAB: libmscab error code: %d\n", cabd->last_error(cabd));
@ -721,21 +713,12 @@ static int cli_scanmscab(int desc, const char **virname, long int *scanned, cons
static int cli_scanhtml(int desc, const char **virname, long int *scanned, const struct cl_node *root, const struct cl_limits *limits, unsigned int options, int *arec, int *mrec)
{
char *tempname, fullname[1024];
const char *tmpdir;
int ret=CL_CLEAN, fd;
cli_dbgmsg("in cli_scanhtml()\n");
if((tmpdir = getenv("TMPDIR")) == NULL)
#ifdef P_tmpdir
tmpdir = P_tmpdir;
#else
tmpdir = "/tmp";
#endif
tempname = cli_gentemp(tmpdir);
tempname = cli_gentemp(NULL);
if(mkdir(tempname, 0700)) {
cli_dbgmsg("ScanHTML -> Can't create temporary directory %s\n", tempname);
return CL_ETMPDIR;
@ -996,22 +979,14 @@ static int cli_vba_scandir(const char *dirname, const char **virname, long int *
static int cli_scanole2(int desc, const char **virname, long int *scanned, const struct cl_node *root, const struct cl_limits *limits, unsigned int options, int *arec, int *mrec)
{
const char *tmpdir;
char *dir;
int ret = CL_CLEAN;
cli_dbgmsg("in cli_scanole2()\n");
if((tmpdir = getenv("TMPDIR")) == NULL)
#ifdef P_tmpdir
tmpdir = P_tmpdir;
#else
tmpdir = "/tmp";
#endif
/* generate the temporary directory */
dir = cli_gentemp(tmpdir);
dir = cli_gentemp(NULL);
if(mkdir(dir, 0700)) {
cli_dbgmsg("OLE2: Can't create temporary directory %s\n", dir);
return CL_ETMPDIR;
@ -1039,22 +1014,14 @@ static int cli_scanole2(int desc, const char **virname, long int *scanned, const
static int cli_scantar(int desc, const char **virname, long int *scanned, const struct cl_node *root, const struct cl_limits *limits, unsigned int options, int *arec, int *mrec)
{
const char *tmpdir;
char *dir;
int ret = CL_CLEAN;
cli_dbgmsg("in cli_scantar()\n");
if((tmpdir = getenv("TMPDIR")) == NULL)
#ifdef P_tmpdir
tmpdir = P_tmpdir;
#else
tmpdir = "/tmp";
#endif
/* generate temporary directory */
dir = cli_gentemp(tmpdir);
dir = cli_gentemp(NULL);
if(mkdir(dir, 0700)) {
cli_errmsg("Tar: Can't create temporary directory %s\n", dir);
return CL_ETMPDIR;
@ -1074,22 +1041,13 @@ static int cli_scantar(int desc, const char **virname, long int *scanned, const
static int cli_scanmschm(int desc, const char **virname, long int *scanned, const struct cl_node *root, const struct cl_limits *limits, unsigned int options, int *arec, int *mrec)
{
const char *tmpdir;
char *tempname;
int ret = CL_CLEAN;
cli_dbgmsg("in cli_scanmschm()\n");
if((tmpdir = getenv("TMPDIR")) == NULL)
#ifdef P_tmpdir
tmpdir = P_tmpdir;
#else
tmpdir = "/tmp";
#endif
tempname = cli_gentemp(tmpdir);
tempname = cli_gentemp(NULL);
if(mkdir(tempname, 0700)) {
cli_dbgmsg("CHM: Can't create temporary directory %s\n", tempname);
return CL_ETMPDIR;
@ -1107,21 +1065,12 @@ static int cli_scanmschm(int desc, const char **virname, long int *scanned, cons
static int cli_scanscrenc(int desc, const char **virname, long int *scanned, const struct cl_node *root, const struct cl_limits *limits, unsigned int options, int *arec, int *mrec)
{
const char *tmpdir;
char *tempname;
int ret = CL_CLEAN;
cli_dbgmsg("in cli_scanscrenc()\n");
if((tmpdir = getenv("TMPDIR")) == NULL)
#ifdef P_tmpdir
tmpdir = P_tmpdir;
#else
tmpdir = "/tmp";
#endif
tempname = cli_gentemp(tmpdir);
tempname = cli_gentemp(NULL);
if(mkdir(tempname, 0700)) {
cli_dbgmsg("CHM: Can't create temporary directory %s\n", tempname);
return CL_ETMPDIR;
@ -1139,45 +1088,37 @@ static int cli_scanscrenc(int desc, const char **virname, long int *scanned, con
static int cli_scanmail(int desc, const char **virname, long int *scanned, const struct cl_node *root, const struct cl_limits *limits, unsigned int options, int *arec, int *mrec)
{
const char *tmpdir;
char *dir;
int ret;
cli_dbgmsg("Starting cli_scanmail(), mrec == %d, arec == %d\n", *mrec, *arec);
if((tmpdir = getenv("TMPDIR")) == NULL)
#ifdef P_tmpdir
tmpdir = P_tmpdir;
#else
tmpdir = "/tmp";
#endif
/* generate the temporary directory */
dir = cli_gentemp(tmpdir);
if(mkdir(dir, 0700)) {
cli_dbgmsg("Mail: Can't create temporary directory %s\n", dir);
free(dir);
return CL_ETMPDIR;
}
/*
* Extract the attachments into the temporary directory
*/
if((ret = cli_mbox(dir, desc, options))) {
if(!cli_leavetemps_flag)
cli_rmdirs(dir);
free(dir);
return ret;
}
ret = cli_scandir(dir, virname, scanned, root, limits, options, arec, mrec);
/* generate the temporary directory */
dir = cli_gentemp(NULL);
if(mkdir(dir, 0700)) {
cli_dbgmsg("Mail: Can't create temporary directory %s\n", dir);
free(dir);
return CL_ETMPDIR;
}
/*
* Extract the attachments into the temporary directory
*/
if((ret = cli_mbox(dir, desc, options))) {
if(!cli_leavetemps_flag)
cli_rmdirs(dir);
free(dir);
return ret;
}
ret = cli_scandir(dir, virname, scanned, root, limits, options, arec, mrec);
if(!cli_leavetemps_flag)
cli_rmdirs(dir);
free(dir);
return ret;
}
int cli_magic_scandesc(int desc, const char **virname, long int *scanned, const struct cl_node *root, const struct cl_limits *limits, unsigned int options, int *arec, int *mrec)

@ -800,20 +800,10 @@ static char *ppt_stream_iter(int fd)
{
atom_header_t atom_header;
uint32_t ole_id;
char *tmpdir, *out_dir;
char *out_dir;
/* Create a directory to store the extracted OLE2 objects */
tmpdir = getenv("TMPDIR");
if(tmpdir == NULL)
#ifdef P_tmpdir
tmpdir = P_tmpdir;
#else
tmpdir = "/tmp";
#endif
/* generate the temporary directory */
out_dir = cli_gentemp(tmpdir);
out_dir = cli_gentemp(NULL);
if(mkdir(out_dir, 0700)) {
printf("ScanOLE2 -> Can't create temporary directory %s\n", out_dir);
free(out_dir);

Loading…
Cancel
Save