2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-31 14:35:26 +00:00

fixed a bug in rolling timestamp logfiles

due to comparing logfile suffixes as 32 bit rather than 64 bit
integers, logfiles with timestamp suffixes that should have been
removed when rolling could be left in place. this has been fixed.
This commit is contained in:
Evan Hunt
2021-10-12 16:31:47 -07:00
parent 76baed3343
commit 9a9e906306
3 changed files with 29 additions and 13 deletions

View File

@@ -25,7 +25,7 @@ options {
logging { logging {
channel default_log { channel default_log {
buffered no; buffered no;
file "named_ts" versions 10 size 1000 suffix timestamp; # small size file "named_ts" versions 3 size 1000 suffix timestamp; # small size
severity debug 100; severity debug 100;
print-time yes; print-time yes;
}; };

View File

@@ -187,10 +187,22 @@ ret=0
copy_setports ns1/named.tsconf.in ns1/named.conf copy_setports ns1/named.tsconf.in ns1/named.conf
# a seconds since epoch version number # a seconds since epoch version number
touch ns1/named_ts.1480039317 touch ns1/named_ts.1480039317
# a timestamp version number
touch ns1/named_ts.20150101120000120
rndc_reconfig ns1 10.53.0.1 > rndc.out.test$n rndc_reconfig ns1 10.53.0.1 > rndc.out.test$n
$DIG version.bind txt ch @10.53.0.1 -p ${PORT} > dig.out.test$n _found2() (
grep "status: NOERROR" dig.out.test$n > /dev/null || ret=1 $DIG version.bind txt ch @10.53.0.1 -p ${PORT} > dig.out.test$n
test_with_retry -f ns1/named_ts.1480039317 && ret=1 grep "status: NOERROR" dig.out.test$n > /dev/null || ret=1
# we are configured to keep three versions, so the oldest
# timestamped versions should be gone, and there should
# be two new ones.
[ -f ns1/named_ts.1480039317 ] && return 1
[ -f ns1/named_ts.20150101120000120 ] && return 1
set -- ns1/named_ts.*
[ "$#" -eq 2 ] || return 1
)
retry_quiet 5 _found2 || ret=1
if [ "$ret" -ne 0 ]; then echo_i "failed"; fi if [ "$ret" -ne 0 ]; then echo_i "failed"; fi
status=$((status+ret)) status=$((status+ret))

View File

@@ -1088,7 +1088,7 @@ greatest_version(isc_logfile_t *file, int versions, int *greatestp) {
} }
static void 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; int i = 0;
while (i < versions && version < to_keep[i]) { while (i < versions && version < to_keep[i]) {
i++; i++;
@@ -1105,12 +1105,13 @@ insert_sort(int64_t to_keep[], int64_t versions, int version) {
static int64_t static int64_t
last_to_keep(int64_t versions, isc_dir_t *dirp, char *bname, size_t bnamelen) { last_to_keep(int64_t versions, isc_dir_t *dirp, char *bname, size_t bnamelen) {
if (versions <= 0) {
return INT64_MAX;
}
int64_t to_keep[ISC_LOG_MAX_VERSIONS] = { 0 }; int64_t to_keep[ISC_LOG_MAX_VERSIONS] = { 0 };
int64_t version = 0; int64_t version = 0;
if (versions <= 0) {
return (INT64_MAX);
}
if (versions > ISC_LOG_MAX_VERSIONS) { if (versions > ISC_LOG_MAX_VERSIONS) {
versions = ISC_LOG_MAX_VERSIONS; versions = ISC_LOG_MAX_VERSIONS;
} }
@@ -1119,6 +1120,9 @@ last_to_keep(int64_t versions, isc_dir_t *dirp, char *bname, size_t bnamelen) {
*/ */
memset(to_keep, 0, sizeof(to_keep)); memset(to_keep, 0, sizeof(to_keep));
while (isc_dir_read(dirp) == ISC_R_SUCCESS) { while (isc_dir_read(dirp) == ISC_R_SUCCESS) {
char *digit_end = NULL;
char *ename = NULL;
if (dirp->entry.length <= bnamelen || if (dirp->entry.length <= bnamelen ||
strncmp(dirp->entry.name, bname, bnamelen) != 0 || strncmp(dirp->entry.name, bname, bnamelen) != 0 ||
dirp->entry.name[bnamelen] != '.') dirp->entry.name[bnamelen] != '.')
@@ -1126,8 +1130,7 @@ last_to_keep(int64_t versions, isc_dir_t *dirp, char *bname, size_t bnamelen) {
continue; continue;
} }
char *digit_end; ename = &dirp->entry.name[bnamelen + 1];
char *ename = &dirp->entry.name[bnamelen + 1];
version = strtoull(ename, &digit_end, 10); version = strtoull(ename, &digit_end, 10);
if (*digit_end == '\0') { if (*digit_end == '\0') {
insert_sort(to_keep, versions, version); insert_sort(to_keep, versions, version);
@@ -1145,12 +1148,13 @@ last_to_keep(int64_t versions, isc_dir_t *dirp, char *bname, size_t bnamelen) {
static isc_result_t static isc_result_t
remove_old_tsversions(isc_logfile_t *file, int versions) { remove_old_tsversions(isc_logfile_t *file, int versions) {
isc_result_t result; isc_result_t result;
char *bname, *digit_end; char *bname = NULL, *digit_end = NULL;
const char *dirname; const char *dirname = NULL;
int64_t version, last = INT64_MAX; int64_t version, last = INT64_MAX;
size_t bnamelen; size_t bnamelen;
isc_dir_t dir; isc_dir_t dir;
char sep = '/'; char sep = '/';
/* /*
* It is safe to DE_CONST the file.name because it was copied * It is safe to DE_CONST the file.name because it was copied
* with isc_mem_strdup(). * with isc_mem_strdup().