2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-28 13:08:06 +00:00

Fix a logical bug in cfg_print_duration()

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.

(cherry picked from commit 94409101870b689f77452b6324968687d9f3c72f)
This commit is contained in:
Aram Sargsyan 2022-10-17 08:45:09 +00:00
parent e33fdd5c05
commit b6978ccbe3

View 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]);
}