Skip to content
Snippets Groups Projects
Commit d0cb7f39 authored by Libor Peltan's avatar Libor Peltan Committed by Daniel Salzman
Browse files

zscanner: parsing timestamps up to year 2225 (was 2105)

parent 47dfd3d7
Branches
Tags
1 merge request!1427RRSIG: allow timestamps past year 2106
/* Copyright (C) 2021 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2022 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -667,7 +667,7 @@ static const uint16_t days_across_months[] = {
[ 7] = 181, [ 8] = 212, [ 9] = 243, [10] = 273, [11] = 304, [12] = 334,
};
// 0 ~ 1970 ... 135 ~ 2105
// 0 ~ 1970 ... 135 ~ 2105 ... 255 ~ 2225
static const uint8_t is_leap_year[] = {
[ 1] = 0, [ 2] = 1, [ 3] = 0, [ 4] = 0, [ 5] = 0,
[ 6] = 1, [ 7] = 0, [ 8] = 0, [ 9] = 0, [ 10] = 1,
......@@ -696,10 +696,34 @@ static const uint8_t is_leap_year[] = {
[121] = 0, [122] = 1, [123] = 0, [124] = 0, [125] = 0,
[126] = 1, [127] = 0, [128] = 0, [129] = 0, [130] = 0,
[131] = 0, [132] = 0, [133] = 0, [134] = 1, [135] = 0,
[136] = 0, [137] = 0, [138] = 1, [139] = 0, [140] = 0,
[141] = 0, [142] = 1, [143] = 0, [144] = 0, [145] = 0,
[146] = 1, [147] = 0, [148] = 0, [149] = 0, [150] = 1,
[151] = 0, [152] = 0, [153] = 0, [154] = 1, [155] = 0,
[156] = 0, [157] = 0, [158] = 1, [159] = 0, [160] = 0,
[161] = 0, [162] = 1, [163] = 0, [164] = 0, [165] = 0,
[166] = 1, [167] = 0, [168] = 0, [169] = 0, [170] = 1,
[171] = 0, [172] = 0, [173] = 0, [174] = 1, [175] = 0,
[176] = 0, [177] = 0, [178] = 1, [179] = 0, [180] = 0,
[181] = 0, [182] = 1, [183] = 0, [184] = 0, [185] = 0,
[186] = 1, [187] = 0, [188] = 0, [189] = 0, [190] = 1,
[191] = 0, [192] = 0, [193] = 0, [194] = 1, [195] = 0,
[196] = 0, [197] = 0, [198] = 1, [199] = 0, [200] = 0,
[201] = 0, [202] = 1, [203] = 0, [204] = 0, [205] = 0,
[206] = 1, [207] = 0, [208] = 0, [209] = 0, [210] = 1,
[211] = 0, [212] = 0, [213] = 0, [214] = 1, [215] = 0,
[216] = 0, [217] = 0, [218] = 1, [219] = 0, [220] = 0,
[221] = 0, [222] = 1, [223] = 0, [224] = 0, [225] = 0,
[226] = 1, [227] = 0, [228] = 0, [229] = 0, [230] = 0,
[231] = 0, [232] = 0, [233] = 0, [234] = 1, [235] = 0,
[236] = 0, [237] = 0, [238] = 1, [239] = 0, [240] = 0,
[241] = 0, [242] = 1, [243] = 0, [244] = 0, [245] = 0,
[246] = 1, [247] = 0, [248] = 0, [249] = 0, [250] = 1,
[251] = 0, [252] = 0, [253] = 0, [254] = 1, [255] = 0,
};
// 0 ~ 1970 ... 135 ~ 2105
static const uint16_t days_across_years[] = {
// 0 ~ 1970 ... 135 ~ 2105 ... 255 ~ 2225
static const uint32_t days_across_years[] = {
[ 1] = 365, [ 2] = 730, [ 3] = 1096, [ 4] = 1461, [ 5] = 1826,
[ 6] = 2191, [ 7] = 2557, [ 8] = 2922, [ 9] = 3287, [ 10] = 3652,
[ 11] = 4018, [ 12] = 4383, [ 13] = 4748, [ 14] = 5113, [ 15] = 5479,
......@@ -727,6 +751,30 @@ static const uint16_t days_across_years[] = {
[121] = 44195, [122] = 44560, [123] = 44926, [124] = 45291, [125] = 45656,
[126] = 46021, [127] = 46387, [128] = 46752, [129] = 47117, [130] = 47482,
[131] = 47847, [132] = 48212, [133] = 48577, [134] = 48942, [135] = 49308,
[136] = 49673, [137] = 50038, [138] = 50403, [139] = 50769, [140] = 51134,
[141] = 51499, [142] = 51864, [143] = 52230, [144] = 52595, [145] = 52960,
[146] = 53325, [147] = 53691, [148] = 54056, [149] = 54421, [150] = 54786,
[151] = 55152, [152] = 55517, [153] = 55882, [154] = 56247, [155] = 56613,
[156] = 56978, [157] = 57343, [158] = 57708, [159] = 58074, [160] = 58439,
[161] = 58804, [162] = 59169, [163] = 59535, [164] = 59900, [165] = 60265,
[166] = 60630, [167] = 60996, [168] = 61361, [169] = 61726, [170] = 62091,
[171] = 62457, [172] = 62822, [173] = 63187, [174] = 63552, [175] = 63918,
[176] = 64283, [177] = 64648, [178] = 65013, [179] = 65379, [180] = 65744,
[181] = 66109, [182] = 66474, [183] = 66840, [184] = 67205, [185] = 67570,
[186] = 67935, [187] = 68301, [188] = 68666, [189] = 69031, [190] = 69396,
[191] = 69762, [192] = 70127, [193] = 70492, [194] = 70857, [195] = 71223,
[196] = 71588, [197] = 71953, [198] = 72318, [199] = 72684, [200] = 73049,
[201] = 73414, [202] = 73779, [203] = 74145, [204] = 74510, [205] = 74875,
[206] = 75240, [207] = 75606, [208] = 75971, [209] = 76336, [210] = 76701,
[211] = 77067, [212] = 77432, [213] = 77797, [214] = 78162, [215] = 78528,
[216] = 78893, [217] = 79258, [218] = 79623, [219] = 79989, [220] = 80354,
[221] = 80719, [222] = 81084, [223] = 81450, [224] = 81815, [225] = 82180,
[226] = 82545, [227] = 82911, [228] = 83276, [229] = 83641, [230] = 84006,
[231] = 84371, [232] = 84736, [233] = 85101, [234] = 85466, [235] = 85832,
[236] = 86197, [237] = 86562, [238] = 86927, [239] = 87293, [240] = 87658,
[241] = 88023, [242] = 88388, [243] = 88754, [244] = 89119, [245] = 89484,
[246] = 89849, [247] = 90215, [248] = 90580, [249] = 90945, [250] = 91310,
[251] = 91676, [252] = 92041, [253] = 92406, [254] = 92771, [255] = 93137,
};
int date_to_timestamp(uint8_t *buff, uint32_t *timestamp)
......@@ -742,7 +790,7 @@ int date_to_timestamp(uint8_t *buff, uint32_t *timestamp)
minute = 10 * (buff[10] - '0') + (buff[11] - '0');
second = 10 * (buff[12] - '0') + (buff[13] - '0');
if (year < 1970 || year > 2105 || month < 1 || month > 12 || day < 1) {
if (year < 1970 || year > 2225 || month < 1 || month > 12 || day < 1) {
return ZS_BAD_DATE;
} else {
year -= 1970;
......
......@@ -7,7 +7,8 @@ $TTL 1
@ RRSIG TYPE65535 255 255 4294967295 4294967295 4294967295 65535 . AA== ; Maximal numbers
@ RRSIG TYPE0 RSAMD5 0 0 0 0 0 . AA== ; Algorithm mnemonic
@ RRSIG A 0 0 0 19700101000000 0 0 . AA== ; Minimal date format
@ RRSIG A 0 0 0 0 21051231235959 0 . AA== ; Maximal date format (zscanner limit)
@ RRSIG A 0 0 0 0 21051231235959 0 . AA== ; Maximal date format (zscanner original limit)
@ RRSIG A 0 0 0 0 22251231235959 0 . AA== ; Maximal date format (zscanner limit)
@ RRSIG TYPE0 0 0 0 0 0 0 \0320\ \\\"\.\@\*.tld. AA== ; Special chars in domain name
@ RRSIG A 0 0 0 0 0 0 . Zm8= ; One char padding
@ RRSIG A 0 0 0 0 0 0 . Zm9v ; Without padding
......@@ -29,9 +30,9 @@ $TTL 1
@ RRSIG A 0 0 0 9294967296 0 0 . AA== ; Sig. exp. overflow
@ RRSIG A 0 0 0 0 4294967296 0 . AA== ; Sig. inc. overflow
@ RRSIG A 0 0 0 0 0 65536 . AA== ; Key tag overflow
@ RRSIG A 0 0 0 0 21060101000000 0 . AA== ; Date overflow
@ RRSIG A 0 0 0 0 2106010100000x 0 . AA== ; Bad timestamp char
@ RRSIG A 0 0 0 0 210601010000000 0 . AA== ; Bad timestamp length
@ RRSIG A 0 0 0 0 22260101000000 0 . AA== ; Date overflow
@ RRSIG A 0 0 0 0 2226010100000x 0 . AA== ; Bad timestamp char
@ RRSIG A 0 0 0 0 222601010000000 0 . AA== ; Bad timestamp length
@ RRSIG A 0 0 0 0 0 0 a% AA== ; Bad domain char
@ RRSIG A 0 0 0 0 0 0 . A ; Continuous block length must be multiple of 4
@ RRSIG A 0 0 0 0 0 0 . AB ; Continuous block length must be multiple of 4
......
......@@ -38,6 +38,12 @@ OWNER=00
CLASS=0001
RRTTL=00000001
RTYPE=002E
RDATA=000100000000000000000000E1853CFF00000000
------
OWNER=00
CLASS=0001
RRTTL=00000001
RTYPE=002E
RDATA=000000000000000000000000000000000000082030205C222E402A03746C640000
------
OWNER=00
......
......@@ -140,7 +140,7 @@ int test_date_to_timestamp(void)
tzset();
// Get maximal allowed timestamp.
strptime("21051231235959", "%Y%m%d%H%M%S", &tm);
strptime("22251231235959", "%Y%m%d%H%M%S", &tm);
max_timestamp = mktime(&tm);
// Testing loop over whole input interval.
......@@ -159,11 +159,11 @@ int test_date_to_timestamp(void)
// Some continuous logging.
if (ref_timestamp % 10000000 == 0) {
val1 = ref_timestamp;
printf("%s = %"PRIu64"\n", buffer, val1);
printf("%s = %"PRIu32"\n", buffer, (uint32_t)val1);
}
// Comparing results.
if (ref_timestamp != test_timestamp) {
if ((uint32_t)ref_timestamp != test_timestamp) {
val1 = ref_timestamp;
if (ref_timestamp > test_timestamp) {
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment