Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ISC Open Source Projects
Kea
Commits
e441d6b0
Commit
e441d6b0
authored
Nov 30, 2012
by
JINMEI Tatuya
Browse files
[2382] warn if RDATA immediately followed by EOF
parent
0ad163bb
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/lib/dns/rdata.cc
View file @
e441d6b0
...
...
@@ -138,27 +138,33 @@ createRdata(const RRType& rrtype, const RRClass& rrclass,
// finer.
fromtextError
(
error_issued
,
lexer
,
callbacks
,
NULL
,
ex
.
what
());
}
// Other exceptions mean a serious implementation bug; it doesn't make
// sense to catch and try to recover from them here. Just propagate.
// Other exceptions mean a serious implementation bug or fatal system
// error; it doesn't make sense to catch and try to recover from them
// here. Just propagate.
// Consume to end of line / file.
// If not at end of line initially set error code.
// Call callback via fromtextError once if there was an error.
do
{
const
MasterToken
&
token
=
lexer
.
getNextToken
();
if
(
token
.
getType
()
!=
MasterToken
::
END_OF_LINE
&&
token
.
getType
()
!=
MasterToken
::
END_OF_FILE
)
{
switch
(
token
.
getType
())
{
case
MasterToken
::
END_OF_LINE
:
return
(
rdata
);
case
MasterToken
::
END_OF_FILE
:
callbacks
.
warning
(
lexer
.
getSourceName
(),
lexer
.
getSourceLine
(),
"file does not end with newline"
);
return
(
rdata
);
default:
rdata
.
reset
();
// we'll return NULL
if
(
!
error_issued
)
{
fromtextError
(
error_issued
,
lexer
,
callbacks
,
&
token
,
"extra input text"
);
}
}
else
{
// reached EOL or EOF
break
;
fromtextError
(
error_issued
,
lexer
,
callbacks
,
&
token
,
"extra input text"
);
// Continue until we see EOL or EOF
}
}
while
(
true
);
return
(
rdata
);
// We shouldn't reach here
assert
(
false
);
return
(
RdataPtr
());
// add explicit return to silence some compilers
}
int
...
...
src/lib/dns/tests/rdata_unittest.cc
View file @
e441d6b0
...
...
@@ -136,6 +136,7 @@ TEST_F(RdataTest, createRdataWithLexer) {
ss
<<
aaaa_rdata
.
toText
()
<<
" extra token
\n
"
;
// 2 extra tokens
ss
<<
")
\n
"
;
// causing lexer error in parsing the RDATA text
ss
<<
"192.0.2.1
\n
"
;
// semantics error: IPv4 address is given for AAAA
ss
<<
aaaa_rdata
.
toText
();
// valid, but end with EOF, not EOL
lexer
.
pushSource
(
ss
);
CreateRdataCallback
callback
;
...
...
@@ -185,6 +186,15 @@ TEST_F(RdataTest, createRdataWithLexer) {
callback
.
check
(
src_name
,
5
,
CreateRdataCallback
::
ERROR
,
"createRdata from text failed: Failed to convert "
"'192.0.2.1' to IN/AAAA RDATA"
);
// Input is valid and parse will succeed, but with a warning that the
// file is not ended with a newline.
callback
.
clear
();
rdata
=
createRdata
(
RRType
::
AAAA
(),
RRClass
::
IN
(),
lexer
,
NULL
,
MasterLoader
::
MANY_ERRORS
,
callbacks
);
EXPECT_EQ
(
0
,
aaaa_rdata
.
compare
(
*
rdata
));
callback
.
check
(
src_name
,
6
,
CreateRdataCallback
::
WARN
,
"file does not end with newline"
);
}
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment