From: Aram Sargsyan Date: Mon, 17 Oct 2022 08:45:26 +0000 (+0000) Subject: Fix an off-by-one error in cfg_print_duration() X-Git-Tag: v9.19.7~57^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=dc55f1ebb91e01979883678e620aa999443522c1;p=thirdparty%2Fbind9.git Fix an off-by-one error in cfg_print_duration() The cfg_print_duration() checks added previously in the 'duration_test' unit test uncovered a bug in cfg_print_duration(). When calculating the current 'str' pointer of the generated text in the buffer 'buf', it erroneously adds 1 byte to compensate for that part's indicator character. For example, to add 12 minutes, it needs to add 2 + 1 = 3 characters, where 2 is the length of "12", and 1 is the length of "M" (for minute). The mistake was that the length of the indicator is already included in 'durationlen[i]', so there is no need to calculate it again. In the result of this mistake the current pointer can advance further than needed and end up after the zero-byte instead of right on it, which essentially cuts off any further generated text. For example, for a 5 minutes and 30 seconds duration, instead of having this: 'P', 'T', '5', 'M', '3', '0', 'S', '\0' The function generates this: 'P', 'T', '5', 'M', '\0', '3', '0', 'S', '\0' Fix the bug by adding to 'str' just 'durationlen[i]' instead of 'durationlen[i] + 1'. --- diff --git a/lib/isccfg/parser.c b/lib/isccfg/parser.c index d27e6e599a8..4ce73dd0b91 100644 --- a/lib/isccfg/parser.c +++ b/lib/isccfg/parser.c @@ -1096,7 +1096,7 @@ cfg_print_duration(cfg_printer_t *pctx, const cfg_obj_t *obj) { if (duration.parts[i] > 0) { snprintf(str, durationlen[i] + 2, "%u%c", (uint32_t)duration.parts[i], indicators[i]); - str += durationlen[i] + 1; + str += durationlen[i]; } if (i == 3 && T) { snprintf(str, 2, "T");