Merge pull request #1033 from pi-hole/fix/maxdb_overflow

Config option MAXDBDAYS fixes and tweaks
This commit is contained in:
DL6ER
2021-01-18 22:09:18 +01:00
committed by GitHub
2 changed files with 15 additions and 2 deletions
+14 -1
View File
@@ -17,6 +17,9 @@
// saveport()
#include "api/socket.h"
// INT_MAX
#include <limits.h>
ConfigStruct config;
FTLFileNamesStruct FTLfiles = {
// Default path for config file (regular installations)
@@ -132,12 +135,22 @@ void read_FTLconf(void)
buffer = parse_FTLconf(fp, "MAXDBDAYS");
int value = 0;
const int maxdbdays_max = INT_MAX / 24 / 60 / 60;
if(buffer != NULL && sscanf(buffer, "%i", &value))
if(value >= 0)
{
// Prevent possible overflow
if(value > maxdbdays_max)
value = maxdbdays_max;
// Only use valid values
if(value == -1 || value >= 0)
config.maxDBdays = value;
}
if(config.maxDBdays == 0)
logg(" MAXDBDAYS: --- (DB disabled)");
else if(config.maxDBdays == -1)
logg(" MAXDBDAYS: --- (cleaning disabled)");
else
logg(" MAXDBDAYS: max age for stored queries is %i days", config.maxDBdays);
+1 -1
View File
@@ -54,7 +54,7 @@ void *DB_thread(void *val)
unlock_shm();
// Check if GC should be done on the database
if(DBdeleteoldqueries)
if(DBdeleteoldqueries && config.maxDBdays != -1)
{
// No thread locks needed
delete_old_queries_in_DB();