When ts1.tv_nsec < ts0.tv_nsec (nanosecond counter wraps across a second
boundary), the unsigned subtraction produced a huge positive value instead
of a small negative one. Compute the full difference in signed int64_t
nanoseconds first, then convert to unsigned microseconds.
Signed-off-by: Dominik <dl6er@dl6er.de>
findClientID() increments client->count for every incoming query,
including those that are immediately refused by the rate-limiter.
Because rate-limited queries never create a query record, GC (gc.c)
has nothing to decrement and the count inflates permanently.
Undo the increment before the early return so the "Top Clients
(total)" counter stays consistent with what Pi-hole actually
processed.
Fixes#2810
Signed-off-by: Dominik <dl6er@dl6er.de>
memdb_queries_count and diskdb_queries_count are declared as uint64_t.
In delete_old_queries_from_db(), both counters are decremented by
`deleted` (int64_t from sqlite3_changes64). If the counter is already
at 0 — which can happen when import_queries_from_disk() fails and
resets the counter to 0 mid-import — subtracting any positive `deleted`
value wraps the counter to UINT64_MAX (≈1.84×10¹⁹).
db_counts() returns these counters as sqlite3_int64 (signed), so
UINT64_MAX becomes -1. The /api/queries endpoint then casts -1 to
unsigned long for recordsTotal, producing the observed
1.8446744073709552E+19 value and making the query log appear to have
millions of pages.
Fix: clamp the subtraction to 0 instead of allowing underflow, using
a guarded conditional assignment.
Signed-off-by: Dominik <dl6er@dl6er.de>
`pihole-FTL --config webserver.api` previously silently omitted
`webserver.api.totp_secret` because it carries FLAG_WRITE_ONLY,
making it impossible to tell from the CLI whether 2FA was enabled.
Write-only config items are now included in CLI output but rendered
as "********" when the secret is set (consistent with how
`webserver.api.password` is displayed), or left blank when unset.
The actual secret value is never exposed.
Fixes#2435
Signed-off-by: Dominik <dl6er@dl6er.de>
Replace the glibc-only execinfo.h backtrace with _Unwind_Backtrace
from GCC's libgcc, which works on glibc and musl, static-pie and
dynamic, across all supported architectures.
Key design decisions:
- __ehdr_start (GNU ld linker symbol) gives the PIE load base
reliably on all targets, replacing dl_iterate_phdr which does not
enumerate the main executable consistently on musl static builds
- SOURCE_ROOT compile definition strips the build machine prefix so
backtraces show project-relative paths (src/signals.c:42)
- dladdr() resolves dynamic symbol names from .dynsym for stripped
shared-library frames; /proc/self/maps provides the library name
as fallback when no symbol is exported
- Each frame is logged as a single line:
#N func_name src/file.c:line (resolved)
#N 0xADDRESS (libc.so.6 sym+off) (unresolved)
New subcommands:
- crash: triggers a deterministic SIGSEGV via mmap(PROT_NONE)
(not UB, not elided by the optimizer, not caught by
sanitizers) to validate the crash handler end-to-end
- backtrace: prints a live backtrace without crashing, for manual
inspection on a given build or platform
CI: add check_crash() to test/arch_test.sh, called unconditionally
for every architecture to verify the handler fires and a backtrace
is produced.
Bug fixes:
- removePID(): guard config.files.pid.v.s != NULL before fopen()
to prevent a secondary SIGSEGV when config was never loaded
(e.g. crash/backtrace subcommands)
- signal_handler(): fflush(stdout) immediately after generate_backtrace()
so the output is preserved even if cleanup() faults on uninitialized
state before exit() can flush stdio
Signed-off-by: Dominik <dl6er@dl6er.de>
Building with a custom toolchain (GCC 15, uClibc, kernel headers 5.10)
fails in netlink.c with errors like these:
pihole-ftl-6.5/src/signals.c:214:30: error: ‘BUS_MCEERR_AR’ undeclared (first use in this function)
214 | case BUS_MCEERR_AR: log_info(" with code: BUS_MCEERR_AR (Hardware memory error: action required)"); break;
| ^~~~~~~~~~~~~
pihole-ftl-6.5/src/signals.c:214:30: note: each undeclared identifier is reported only once for each function it appears in
pihole-ftl-6.5/src/signals.c:215:30: error: ‘BUS_MCEERR_AO’ undeclared (first use in this function)
215 | case BUS_MCEERR_AO: log_info(" with code: BUS_MCEERR_AO (Hardware memory error: action optional)"); break;
| ^~~~~~~~~~~~~
Bracket undeclared symbols with precompiler directives.
Signed-off-by: Andreas Ziegler <15275159+aeolio@users.noreply.github.com>
Building with a custom toolchain (GCC 15, uClibc, kernel headers 5.10)
fails in netlink.c with errors like these:
pihole-ftl-6.5/src/tools/netlink_consts.h:40:11: error: ‘ARPHRD_MCTP’ undeclared here (not in a function); did you mean ‘ARPHRD_FCPP’?
40 | { ARPHRD_MCTP, "mctp" },
| ^~~~~~~~~~~
| ARPHRD_FCPP
pihole-ftl-6.5/src/tools/netlink_consts.h:148:11: error: ‘RTPROT_OPENR’ undeclared here (not in a function); did you mean ‘RTPROT_OSPF’?
148 | { RTPROT_OPENR, "openr" },
| ^~~~~~~~~~~~
| RTPROT_OSPF
Bracket undeclared symbols with precompiler directives.
Signed-off-by: Andreas Ziegler <15275159+aeolio@users.noreply.github.com>
The __GLIBC__ logic to detect stack backtracing capability fails for
uClibc, because uClibc also defines these symbols, but backtrace
functionality is optional.
pihole-ftl-6.5/src/signals.c:13:10: fatal error: execinfo.h: No such file or directory
13 | #include <execinfo.h>
| ^~~~~~~~~~~~
Instead of adding unreadable preprocessor exceptions, have CMake detect
execinfo.h and use a appropriate preprocessor symbol.
Signed-off-by: Andreas Ziegler <15275159+aeolio@users.noreply.github.com>
The __GLIBC__ version check causes problems with uClibc, because
this library also defines these variables, but the numbering is not
consistent with GNU libc. This prevents the inclusion of sys/random.h
in a uClibc toolchain, even if the file is present
Instead let CMake detect sys/random.h and control header inclusion
with a preprocessor symbol.
Signed-off-by: Andreas Ziegler <15275159+aeolio@users.noreply.github.com>
If sys/random.h cannot be found, the build terminates with this error:
pihole-ftl-6.5/src/config/password.c: In function ‘get_secure_randomness’:
pihole-ftl-6.5/src/config/password.c:100:52: error: ‘GRND_NONBLOCK’ undeclared (first use in this function); did you mean ‘SOCK_NONBLOCK’?
100 | result = getrandom(buffer, length, GRND_NONBLOCK);
| ^~~~~~~~~~~~~
| SOCK_NONBLOCK
Add the missing definition of GRND_NONBLOCK in daemon.h.
Signed-off-by: Andreas Ziegler <15275159+aeolio@users.noreply.github.com>
Most cross-compilation tools terminate the build, when they encounter
unsafe (e.g. absolute) paths in include directives, because that might
leak host components into the target. Buildroot fails with:
i586-buildroot-linux-uclibc-gcc: ERROR: unsafe header/library path used in cross-compilation: '-I/usr/local/include'
Remove offending path snippet to correspond with all other include
definitions in Pi-hole/FTL.
Signed-off-by: Andreas Ziegler <15275159+aeolio@users.noreply.github.com>
Commit 3b45213 (Implement automatic TLS/SSL certificate renewals) [1]
introduced functionality that requires mbedtls, but mbedtls is an
optional dependency. This leads to the following compilation error:
pihole-ftl-6.5/src/webserver/webserver.c:36:10: fatal error: mbedtls/ssl_ciphersuites.h: No such file or directory
36 | #include <mbedtls/ssl_ciphersuites.h>
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
Use the HAVE_MBEDTLS preprocessor symbol to assert that certificate related
code is only included if mbedtls is present in the build.
[1] https://github.com/pi-hole/FTL/commit/3b45213
Signed-off-by: Andreas Ziegler <15275159+aeolio@users.noreply.github.com>
Readline and Mbed TLS support are optional dependencies. CMake detects
them, and automatically includes them if they are found. If this is not
intended, currently the only way is to manually delete these liraries
from the build system. While the default behaviour is beneficial, a more
resilient method is looked for to exclude dependencies from the build.
Introduce CMake options for both dependencies, that allow controlling
build inclusion by setting a build variable.
Signed-off-by: Andreas Ziegler <15275159+aeolio@users.noreply.github.com>