mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-08-29 13:38:26 +00:00
make ISO8601 duration parsing case-insensitive for robustness
This commit is contained in:
parent
6504e7da95
commit
09e061aef7
@ -11,6 +11,7 @@
|
||||
|
||||
/*! \file */
|
||||
|
||||
#include <ctype.h>
|
||||
#include <inttypes.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
@ -1180,16 +1181,16 @@ duration_fromtext(isc_textregion_t *source, cfg_duration_t *duration) {
|
||||
}
|
||||
|
||||
/* Every duration starts with 'P' */
|
||||
P = strchr(str, 'P');
|
||||
P = strpbrk(str, "Pp");
|
||||
if (P == NULL) {
|
||||
return (ISC_R_BADNUMBER);
|
||||
}
|
||||
|
||||
/* Record the time indicator. */
|
||||
T = strchr(str, 'T');
|
||||
T = strpbrk(str, "Tt");
|
||||
|
||||
/* Record years. */
|
||||
X = strchr(str, 'Y');
|
||||
X = strpbrk(str, "Yy");
|
||||
if (X != NULL) {
|
||||
duration->parts[0] = atoi(str+1);
|
||||
str = X;
|
||||
@ -1197,7 +1198,7 @@ duration_fromtext(isc_textregion_t *source, cfg_duration_t *duration) {
|
||||
}
|
||||
|
||||
/* Record months. */
|
||||
X = strchr(str, 'M');
|
||||
X = strpbrk(str, "Mm");
|
||||
|
||||
/*
|
||||
* M could be months or minutes. This is months if there is no time
|
||||
@ -1210,7 +1211,7 @@ duration_fromtext(isc_textregion_t *source, cfg_duration_t *duration) {
|
||||
}
|
||||
|
||||
/* Record days. */
|
||||
X = strchr(str, 'D');
|
||||
X = strpbrk(str, "Dd");
|
||||
if (X != NULL) {
|
||||
duration->parts[3] = atoi(str+1);
|
||||
str = X;
|
||||
@ -1224,7 +1225,7 @@ duration_fromtext(isc_textregion_t *source, cfg_duration_t *duration) {
|
||||
}
|
||||
|
||||
/* Record hours. */
|
||||
X = strchr(str, 'H');
|
||||
X = strpbrk(str, "Hh");
|
||||
if (X != NULL && T != NULL) {
|
||||
duration->parts[4] = atoi(str+1);
|
||||
str = X;
|
||||
@ -1232,7 +1233,7 @@ duration_fromtext(isc_textregion_t *source, cfg_duration_t *duration) {
|
||||
}
|
||||
|
||||
/* Record minutes. */
|
||||
X = strrchr(str, 'M');
|
||||
X = strpbrk(str, "Mm");
|
||||
|
||||
/*
|
||||
* M could be months or minutes. This is minutes if there is a time
|
||||
@ -1245,7 +1246,7 @@ duration_fromtext(isc_textregion_t *source, cfg_duration_t *duration) {
|
||||
}
|
||||
|
||||
/* Record seconds. */
|
||||
X = strchr(str, 'S');
|
||||
X = strpbrk(str, "Ss");
|
||||
if (X != NULL && T != NULL) {
|
||||
duration->parts[6] = atoi(str+1);
|
||||
str = X;
|
||||
@ -1253,7 +1254,7 @@ duration_fromtext(isc_textregion_t *source, cfg_duration_t *duration) {
|
||||
}
|
||||
|
||||
/* Or is the duration configured in weeks? */
|
||||
W = strchr(buf, 'W');
|
||||
W = strpbrk(buf, "Ww");
|
||||
if (W != NULL) {
|
||||
if (not_weeks) {
|
||||
/* Mix of weeks and other indicators is not allowed */
|
||||
@ -1280,7 +1281,7 @@ parse_duration(cfg_parser_t *pctx, cfg_obj_t **ret) {
|
||||
|
||||
duration.unlimited = false;
|
||||
|
||||
if (TOKEN_STRING(pctx)[0] == 'P') {
|
||||
if (toupper(TOKEN_STRING(pctx)[0]) == 'P') {
|
||||
result = duration_fromtext(&pctx->token.value.as_textregion,
|
||||
&duration);
|
||||
duration.iso8601 = true;
|
||||
|
@ -110,24 +110,24 @@ cfg_obj_asduration_test(void **state) {
|
||||
duration_conf_t durations[] = {
|
||||
{ .string = "PT0S", .time = 0 },
|
||||
{ .string = "PT42S", .time = 42 },
|
||||
{ .string = "PT10M", .time = 600 },
|
||||
{ .string = "PT10M4S", .time = 604 },
|
||||
{ .string = "PT2H", .time = 7200 },
|
||||
{ .string = "PT2H3S", .time = 7203 },
|
||||
{ .string = "PT2H1M3S", .time = 7263 },
|
||||
{ .string = "P7D", .time = 604800 },
|
||||
{ .string = "P7DT2H", .time = 612000 },
|
||||
{ .string = "PT10m", .time = 600 },
|
||||
{ .string = "PT10m4S", .time = 604 },
|
||||
{ .string = "pT2H", .time = 7200 },
|
||||
{ .string = "Pt2H3S", .time = 7203 },
|
||||
{ .string = "PT2h1m3s", .time = 7263 },
|
||||
{ .string = "p7d", .time = 604800 },
|
||||
{ .string = "P7DT2h", .time = 612000 },
|
||||
{ .string = "P2W", .time = 1209600 },
|
||||
{ .string = "P3M", .time = 8035200 },
|
||||
{ .string = "P3MT10M", .time = 8035800 },
|
||||
{ .string = "P5Y", .time = 157680000 },
|
||||
{ .string = "p5y", .time = 157680000 },
|
||||
{ .string = "P5YT2H", .time = 157687200 },
|
||||
{ .string = "P1Y1M1DT1H1M1S", .time = 34304461 },
|
||||
{ .string = "0", .time = 0 },
|
||||
{ .string = "30", .time = 30 },
|
||||
{ .string = "42s", .time = 42 },
|
||||
{ .string = "10m", .time = 600 },
|
||||
{ .string = "2h", .time = 7200 },
|
||||
{ .string = "2H", .time = 7200 },
|
||||
{ .string = "7d", .time = 604800 },
|
||||
{ .string = "2w", .time = 1209600 },
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user