Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clam 2612 Fix DatabaseCustomURL CVD prune bug, and add 'valhalla' optional database (1.3.1) #1238

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 47 additions & 2 deletions freshclam/freshclam.c
Original file line number Diff line number Diff line change
Expand Up @@ -1027,7 +1027,7 @@ fc_error_t get_official_database_lists(
uint32_t i;

const char *hardcodedStandardDatabaseList[] = {"daily", "main", "bytecode"};
const char *hardcodedOptionalDatabaseList[] = {"safebrowsing", "test"};
const char *hardcodedOptionalDatabaseList[] = {"safebrowsing", "test", "valhalla"};

if ((NULL == standardDatabases) || (NULL == nStandardDatabases) || (NULL == optionalDatabases) || (NULL == nOptionalDatabases)) {
mprintf(LOGG_ERROR, "get_official_database_lists: Invalid arguments.\n");
Expand Down Expand Up @@ -1453,6 +1453,10 @@ fc_error_t perform_database_update(
uint32_t nUpdated = 0;
uint32_t nTotalUpdated = 0;

uint32_t i;
char **doNotPruneDatabaseList = NULL;
uint32_t nDoNotPruneDatabases = 0;

STATBUF statbuf;

if (NULL == serverList) {
Expand All @@ -1473,7 +1477,38 @@ fc_error_t perform_database_update(
* Prune database directory of official databases
* that are no longer available or no longer desired.
*/
(void)fc_prune_database_directory(databaseList, nDatabases);

// include the URL databases in the prune process
doNotPruneDatabaseList = (char **)malloc(sizeof(char *) * (nDatabases + nUrlDatabases));
if (NULL == doNotPruneDatabaseList) {
logg(LOGG_ERROR, "perform_database_update: Can't allocate memory for doNotPruneDatabaseList\n");
status = FC_EMEM;
goto done;
}

for (i = 0; i < nDatabases; i++) {
doNotPruneDatabaseList[i] = strdup(databaseList[i]);
if (doNotPruneDatabaseList[i] == NULL) {
logg(LOGG_ERROR, "perform_database_update: Can't allocate memory for database name in doNotPruneDatabaseList\n");
status = FC_EMEM;
goto done;
}
}
nDoNotPruneDatabases = nDatabases;

for (i = 0; i < nUrlDatabases; i++) {
// Only append the URL databases that end with '.cvd'
if (strlen(urlDatabaseList[i]) > 4 && 0 == strcasecmp(urlDatabaseList[i] + strlen(urlDatabaseList[i]) - 4, ".cvd")) {
const char *startOfFilename = strrchr(urlDatabaseList[i], '/') + 1;
if (NULL != startOfFilename) {
// Add the base database name to the do-not-prune list, excluding the '.cvd' extension.
doNotPruneDatabaseList[nDatabases + i] = CLI_STRNDUP(startOfFilename, strlen(startOfFilename) - strlen(".cvd"));
nDoNotPruneDatabases++;
}
}
}

(void)fc_prune_database_directory(doNotPruneDatabaseList, nDoNotPruneDatabases);
}

/*
Expand Down Expand Up @@ -1544,6 +1579,16 @@ fc_error_t perform_database_update(

done:

// Free up the database list
if (NULL != doNotPruneDatabaseList) {
for (i = 0; i < nDoNotPruneDatabases; i++) {
free(doNotPruneDatabaseList[i]);
doNotPruneDatabaseList[i] = NULL;
}
free(doNotPruneDatabaseList);
doNotPruneDatabaseList = NULL;
}

if (LSTAT(g_freshclamTempDirectory, &statbuf) != -1) {
/* Remove temp directory */
if (*g_freshclamTempDirectory) {
Expand Down
Loading