mirror of
https://github.com/pi-hole/FTL.git
synced 2024-10-26 16:52:18 +02:00
Merge pull request #1033 from pi-hole/fix/maxdb_overflow
Config option MAXDBDAYS fixes and tweaks
This commit is contained in:
+14
-1
@@ -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);
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user