Skip to content

Commit a7d2696

Browse files
committed
Fix bug in NSEC RDATA check
1 parent 46c3b11 commit a7d2696

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

src/generic/types.h

+6-7
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,12 @@ static really_inline int32_t parse_text(
6767
{ { { "", 0 }, code }, 0, false, false, { 0, NULL }, check_generic_rr, parse_unknown_rdata }
6868

6969
#if _WIN32
70-
// FIXME: actually, for all the check functions, an int32_t will more than suffice
70+
// FIXME: check functions can be simplified as int32_t is wide enough to
71+
// represent errors and the maximum length of rdata.
7172
#include <basetsd.h>
7273
typedef SSIZE_T ssize_t;
7374
#endif
7475

75-
// FIXME: check functions can be simplified as int32_t is wide enough to
76-
// represent errors and the maximum length of rdata.
7776
nonnull((1,2,3,4))
7877
static really_inline ssize_t check_bytes(
7978
parser_t *parser,
@@ -170,15 +169,15 @@ static really_inline ssize_t check_nsec(
170169
const size_t length)
171170
{
172171
size_t count = 0;
173-
size_t last_window = 0;
172+
int32_t last_window = -1;
174173

175174
while ((count + 2) < length) {
176-
const size_t window = (size_t)data[0];
175+
const int32_t window = (int32_t)data[0];
177176
const size_t blocks = (size_t)data[1];
178-
if (window < last_window || !window != !last_window)
177+
if (window <= last_window)
179178
SYNTAX_ERROR(parser, "Invalid %s in %s, windows are out-of-order",
180179
NAME(field), NAME(type));
181-
if (blocks > 32)
180+
if (!blocks || blocks > 32)
182181
SYNTAX_ERROR(parser, "Invalid %s in %s, blocks are out-of-bounds",
183182
NAME(field), NAME(type));
184183
count += 2 + blocks;

0 commit comments

Comments
 (0)