Skip to content

Commit 296e7d1

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 c72bb31 commit 296e7d1

File tree

1 file changed

+46
-1
lines changed

1 file changed

+46
-1
lines changed

freshclam/freshclam.c

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1432,6 +1432,10 @@ fc_error_t perform_database_update(
14321432
uint32_t nUpdated = 0;
14331433
uint32_t nTotalUpdated = 0;
14341434

1435+
uint32_t i;
1436+
char **doNotPruneDatabaseList = NULL;
1437+
uint32_t nDoNotPruneDatabases = 0;
1438+
14351439
STATBUF statbuf;
14361440

14371441
if (NULL == serverList) {
@@ -1452,7 +1456,38 @@ fc_error_t perform_database_update(
14521456
* Prune database directory of official databases
14531457
* that are no longer available or no longer desired.
14541458
*/
1455-
(void)fc_prune_database_directory(databaseList, nDatabases);
1459+
1460+
// include the URL databases in the prune process
1461+
doNotPruneDatabaseList = (char **)malloc(sizeof(char *) * (nDatabases + nUrlDatabases));
1462+
if (NULL == doNotPruneDatabaseList) {
1463+
logg(LOGG_ERROR, "perform_database_update: Can't allocate memory for doNotPruneDatabaseList\n");
1464+
status = FC_EMEM;
1465+
goto done;
1466+
}
1467+
1468+
for (i = 0; i < nDatabases; i++) {
1469+
doNotPruneDatabaseList[i] = strdup(databaseList[i]);
1470+
if (doNotPruneDatabaseList[i] == NULL) {
1471+
logg(LOGG_ERROR, "perform_database_update: Can't allocate memory for database name in doNotPruneDatabaseList\n");
1472+
status = FC_EMEM;
1473+
goto done;
1474+
}
1475+
}
1476+
nDoNotPruneDatabases = nDatabases;
1477+
1478+
for (i = 0; i < nUrlDatabases; i++) {
1479+
// Only append the URL databases that end with '.cvd'
1480+
if (strlen(urlDatabaseList[i]) > 4 && 0 == strcasecmp(urlDatabaseList[i] + strlen(urlDatabaseList[i]) - 4, ".cvd")) {
1481+
const char *startOfFilename = strrchr(urlDatabaseList[i], '/') + 1;
1482+
if (NULL != startOfFilename) {
1483+
// Add the base database name to the do-not-prune list, excluding the '.cvd' extension.
1484+
doNotPruneDatabaseList[nDatabases + i] = CLI_STRNDUP(startOfFilename, strlen(startOfFilename) - strlen(".cvd"));
1485+
nDoNotPruneDatabases++;
1486+
}
1487+
}
1488+
}
1489+
1490+
(void)fc_prune_database_directory(doNotPruneDatabaseList, nDoNotPruneDatabases);
14561491
}
14571492

14581493
/*
@@ -1523,6 +1558,16 @@ fc_error_t perform_database_update(
15231558

15241559
done:
15251560

1561+
// Free up the database list
1562+
if (NULL != doNotPruneDatabaseList) {
1563+
for (i = 0; i < nDoNotPruneDatabases; i++) {
1564+
free(doNotPruneDatabaseList[i]);
1565+
doNotPruneDatabaseList[i] = NULL;
1566+
}
1567+
free(doNotPruneDatabaseList);
1568+
doNotPruneDatabaseList = NULL;
1569+
}
1570+
15261571
if (LSTAT(g_freshclamTempDirectory, &statbuf) != -1) {
15271572
/* Remove temp directory */
15281573
if (*g_freshclamTempDirectory) {

0 commit comments

Comments
 (0)