Log purge doesn't work when the log suffixes are timestamps (patch provided)
Log purge doesn't work when the log suffixes are timestamps. Some details: https://lists.isc.org/pipermail/bind-users/2023-March/10449.html
I have invested quite a few hours trying to triage this and I have a patch. The problem is this: the variable "version" is defined as "int64_t" (this is needed because I must support values like "20230322223828199". Nevertheless, the "insert_sort()" "version" parameter is declared as "int". The result is value truncation. Since any winning value (after the sorting) is going to be under 2147483648 (32 bits) and 2147483648 is far lower than "20230322223828199", no logs are selected to be deleted.
A decent compiler would raise a warning when detecting the situation, if warnings were enabled.
The patch is pretty trivial. I can't do merge request because I am not able to fork the repository (This is a new account, apparently I have no permission to fork the repository). I include the diff here, I hope it get some attention.
For some obscure reason this patch is for bind-9.16.35, but I guess it can be trivially ported:
$NetBSD$
--- /home/pbulk/build/net/bind916/work/bind-9.16.35/lib/isc/log.c.orig 2023-03-23 02:17:13.908224941 +0000
+++ /home/pbulk/build/net/bind916/work/bind-9.16.35/lib/isc/log.c
@@ -1101,7 +1101,7 @@ greatest_version(isc_logfile_t *file, in
}
static void
-insert_sort(int64_t to_keep[], int64_t versions, int version) {
+insert_sort(int64_t to_keep[], int64_t versions, int64_t version) {
int i = 0;
while (i < versions && version < to_keep[i]) {
i++;
There is no other caller of "insert_sort()", so this signature change is safe.
Please, apply.
Thanks.