Skip to content

Commit e94446c

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 c2cbb80 commit e94446c

1 file changed

Lines changed: 46 additions & 1 deletion

File tree

freshclam/freshclam.c

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1455,6 +1455,10 @@ fc_error_t perform_database_update(
14551455
uint32_t nUpdated = 0;
14561456
uint32_t nTotalUpdated = 0;
14571457

1458+
uint32_t i;
1459+
char **doNotPruneDatabaseList = NULL;
1460+
uint32_t nDoNotPruneDatabases = 0;
1461+
14581462
STATBUF statbuf;
14591463

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

14811516
/*
@@ -1546,6 +1581,16 @@ fc_error_t perform_database_update(
15461581

15471582
done:
15481583

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

0 commit comments

Comments
 (0)