]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Fix a logical bug in cfg_print_duration()
authorAram Sargsyan <aram@isc.org>
Mon, 17 Oct 2022 08:45:09 +0000 (08:45 +0000)
committerAram Sargsyan <aram@isc.org>
Mon, 17 Oct 2022 08:45:09 +0000 (08:45 +0000)
The cfg_print_duration() function prints a ISO 8601 duration value
converted from an array of integers, where the parts of the date and
time are stored.

durationlen[6], which holds the "seconds" part of the duration, has
a special case in cfg_print_duration() to ensure that when there are
no values in the duration, the result still can be printed as "PT0S",
instead of just "P", so it can be a valid ISO 8601 duration value.

There is a logical error in one of the two special case code paths,
when it checks that no value from the "date" part is defined, and no
"hour" or "minute" from the "time" part are defined.

Because of the error, durationlen[6] can be used uninitialized, in
which case the second parameter passed to snprintf() (which is the
maximum allowed length) can contain a garbage value.

This can not be exploited because the buffer is still big enough to
hold the maximum possible amount of characters generated by the "%u%c"
format string.

Fix the logical bug, and initialize the 'durationlen' array to zeros
to be a little safer from other similar errors.

lib/isccfg/parser.c

index 4ea849e64f3664017ed106d75d8cf99a5fb02443..d27e6e599a82947869025c0c90d22e0e106e3a73 100644 (file)
@@ -1034,7 +1034,7 @@ cfg_print_duration(cfg_printer_t *pctx, const cfg_obj_t *obj) {
        char *str;
        const char *indicators = "YMWDHMS";
        int count, i;
-       int durationlen[7];
+       int durationlen[7] = { 0 };
        isccfg_duration_t duration;
        /*
         * D ? The duration has a date part.
@@ -1066,10 +1066,8 @@ cfg_print_duration(cfg_printer_t *pctx, const cfg_obj_t *obj) {
                        } else {
                                T = true;
                        }
-               } else {
-                       durationlen[i] = 0;
+                       count += durationlen[i];
                }
-               count += durationlen[i];
        }
        /*
         * Special case for seconds which is not taken into account in the
@@ -1107,7 +1105,7 @@ cfg_print_duration(cfg_printer_t *pctx, const cfg_obj_t *obj) {
        }
        /* Special case for seconds. */
        if (duration.parts[6] > 0 ||
-           (!D && !duration.parts[4] && !duration.parts[3])) {
+           (!D && !duration.parts[4] && !duration.parts[5])) {
                snprintf(str, durationlen[6] + 2, "%u%c",
                         (uint32_t)duration.parts[6], indicators[6]);
        }