mirror of
https://github.com/Cisco-Talos/clamav.git
synced 2025-10-19 10:23:17 +00:00
libclamav: avoid loading duplicate databases (bb#1962)
This commit is contained in:
parent
2a7f1cdaf5
commit
02e46f3fdb
4 changed files with 32 additions and 6 deletions
|
@ -1,3 +1,7 @@
|
|||
Thu Apr 22 18:03:30 CEST 2010 (tk)
|
||||
----------------------------------
|
||||
* libclamav: avoid loading duplicate databases (bb#1962)
|
||||
|
||||
Mon Apr 19 17:12:06 EEST 2010 (edwin)
|
||||
-------------------------------------
|
||||
* clamconf: print information about platform and build.
|
||||
|
|
|
@ -554,14 +554,16 @@ int cl_cvdverify(const char *file)
|
|||
return ret;
|
||||
}
|
||||
|
||||
int cli_cvdload(FILE *fs, struct cl_engine *engine, unsigned int *signo, unsigned int options, unsigned int cld, const char *dbname)
|
||||
int cli_cvdload(FILE *fs, struct cl_engine *engine, unsigned int *signo, unsigned int options, unsigned int cld, const char *filename)
|
||||
{
|
||||
struct cl_cvd cvd;
|
||||
struct cl_cvd cvd, dupcvd;
|
||||
FILE *dupfs;
|
||||
int ret;
|
||||
time_t s_time;
|
||||
int cfd;
|
||||
struct cli_dbio dbio;
|
||||
struct cli_dbinfo *dbinfo = NULL;
|
||||
char *dupname;
|
||||
|
||||
cli_dbgmsg("in cli_cvdload()\n");
|
||||
|
||||
|
@ -569,7 +571,27 @@ int cli_cvdload(FILE *fs, struct cl_engine *engine, unsigned int *signo, unsigne
|
|||
if((ret = cli_cvdverify(fs, &cvd, cld)))
|
||||
return ret;
|
||||
|
||||
if(strstr(dbname, "daily.")) {
|
||||
/* check for duplicate db */
|
||||
dupname = cli_strdup(filename);
|
||||
if(!dupname)
|
||||
return CL_EMEM;
|
||||
dupname[strlen(dupname) - 2] = (cld ? 'v' : 'l');
|
||||
if(!access(dupname, R_OK) && (dupfs = fopen(dupname, "rb"))) {
|
||||
if((ret = cli_cvdverify(dupfs, &dupcvd, !cld))) {
|
||||
fclose(dupfs);
|
||||
return ret;
|
||||
}
|
||||
fclose(dupfs);
|
||||
if(dupcvd.version > cvd.version) {
|
||||
cli_warnmsg("Detected duplicate databases %s and %s. The %s database is older and will not be loaded, you should manually remove it from the database directory.\n", filename, dupname, filename);
|
||||
return CL_SUCCESS;
|
||||
} else if(dupcvd.version == cvd.version && !cld) {
|
||||
cli_warnmsg("Detected duplicate databases %s and %s, please manually remove one of them\n", filename, dupname);
|
||||
return CL_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
if(strstr(filename, "daily.")) {
|
||||
time(&s_time);
|
||||
if(cvd.stime > s_time) {
|
||||
if(cvd.stime - (unsigned int ) s_time > 3600) {
|
||||
|
|
|
@ -36,7 +36,7 @@ struct cli_dbio {
|
|||
SHA256_CTX sha256ctx;
|
||||
};
|
||||
|
||||
int cli_cvdload(FILE *fs, struct cl_engine *engine, unsigned int *signo, unsigned int options, unsigned int cld, const char *dbname);
|
||||
int cli_cvdload(FILE *fs, struct cl_engine *engine, unsigned int *signo, unsigned int options, unsigned int cld, const char *filename);
|
||||
int cli_cvdunpack(const char *file, const char *dir);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -2280,10 +2280,10 @@ int cli_load(const char *filename, struct cl_engine *engine, unsigned int *signo
|
|||
ret = cli_loaddb(fs, engine, signo, options, dbio, dbname);
|
||||
|
||||
} else if(cli_strbcasestr(dbname, ".cvd")) {
|
||||
ret = cli_cvdload(fs, engine, signo, options, 0, dbname);
|
||||
ret = cli_cvdload(fs, engine, signo, options, 0, filename);
|
||||
|
||||
} else if(cli_strbcasestr(dbname, ".cld")) {
|
||||
ret = cli_cvdload(fs, engine, signo, options, 1, dbname);
|
||||
ret = cli_cvdload(fs, engine, signo, options, 1, filename);
|
||||
|
||||
} else if(cli_strbcasestr(dbname, ".hdb")) {
|
||||
ret = cli_loadmd5(fs, engine, signo, MD5_HDB, options, dbio, dbname);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue