Skip to content

Commit 3df95e3

Browse files
committed
Freshclam: fix issue DatabaseCustomURL CVD prune issue
If using DatabaseCustomURL to download a CVD that Freshclam doesn't know about, i.e. one that is not in the hardcoded standard or optional database lists in freshclam.c, Freshclam will prune the database and then re-download it. This change makes it so we look for URL's with ".cvd" at the end and then take those into consideration when checking which CVD's (or CLD's) should be pruned. Note that I didn't change the interface to fc_prune_database_directory(). That would have been cleaner, but would've changed the public API and I want to backport this fix.
1 parent 3a5cd1e commit 3df95e3

File tree

1 file changed

+46
-1
lines changed

1 file changed

+46
-1
lines changed

freshclam/freshclam.c

+46-1
Original file line numberDiff line numberDiff line change
@@ -1453,6 +1453,10 @@ fc_error_t perform_database_update(
14531453
uint32_t nUpdated = 0;
14541454
uint32_t nTotalUpdated = 0;
14551455

1456+
uint32_t i;
1457+
char **doNotPruneDatabaseList = NULL;
1458+
uint32_t nDoNotPruneDatabases = 0;
1459+
14561460
STATBUF statbuf;
14571461

14581462
if (NULL == serverList) {
@@ -1473,7 +1477,38 @@ fc_error_t perform_database_update(
14731477
* Prune database directory of official databases
14741478
* that are no longer available or no longer desired.
14751479
*/
1476-
(void)fc_prune_database_directory(databaseList, nDatabases);
1480+
1481+
// include the URL databases in the prune process
1482+
doNotPruneDatabaseList = (char **)malloc(sizeof(char *) * (nDatabases + nUrlDatabases));
1483+
if (NULL == doNotPruneDatabaseList) {
1484+
logg(LOGG_ERROR, "perform_database_update: Can't allocate memory for doNotPruneDatabaseList\n");
1485+
status = FC_EMEM;
1486+
goto done;
1487+
}
1488+
1489+
for (i = 0; i < nDatabases; i++) {
1490+
doNotPruneDatabaseList[i] = strdup(databaseList[i]);
1491+
if (doNotPruneDatabaseList[i] == NULL) {
1492+
logg(LOGG_ERROR, "perform_database_update: Can't allocate memory for database name in doNotPruneDatabaseList\n");
1493+
status = FC_EMEM;
1494+
goto done;
1495+
}
1496+
}
1497+
nDoNotPruneDatabases = nDatabases;
1498+
1499+
for (i = 0; i < nUrlDatabases; i++) {
1500+
// Only append the URL databases that end with '.cvd'
1501+
if (strlen(urlDatabaseList[i]) > 4 && 0 == strcasecmp(urlDatabaseList[i] + strlen(urlDatabaseList[i]) - 4, ".cvd")) {
1502+
const char *startOfFilename = strrchr(urlDatabaseList[i], '/') + 1;
1503+
if (NULL != startOfFilename) {
1504+
// Add the base database name to the do-not-prune list, excluding the '.cvd' extension.
1505+
doNotPruneDatabaseList[nDatabases + i] = CLI_STRNDUP(startOfFilename, strlen(startOfFilename) - strlen(".cvd"));
1506+
nDoNotPruneDatabases++;
1507+
}
1508+
}
1509+
}
1510+
1511+
(void)fc_prune_database_directory(doNotPruneDatabaseList, nDoNotPruneDatabases);
14771512
}
14781513

14791514
/*
@@ -1544,6 +1579,16 @@ fc_error_t perform_database_update(
15441579

15451580
done:
15461581

1582+
// Free up the database list
1583+
if (NULL != doNotPruneDatabaseList) {
1584+
for (i = 0; i < nDoNotPruneDatabases; i++) {
1585+
free(doNotPruneDatabaseList[i]);
1586+
doNotPruneDatabaseList[i] = NULL;
1587+
}
1588+
free(doNotPruneDatabaseList);
1589+
doNotPruneDatabaseList = NULL;
1590+
}
1591+
15471592
if (LSTAT(g_freshclamTempDirectory, &statbuf) != -1) {
15481593
/* Remove temp directory */
15491594
if (*g_freshclamTempDirectory) {

0 commit comments

Comments
 (0)