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
471c6f2d
Commit
471c6f2d
authored
Dec 17, 2012
by
Michal 'vorner' Vaner
Browse files
[2427] Warn on ambiguous initial whitespace name
Which happens after the $INCLUDE directive.
parent
3adc5a44
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/lib/dns/master_loader.cc
View file @
471c6f2d
...
...
@@ -69,6 +69,7 @@ public:
initialized_
(
false
),
ok_
(
true
),
many_errors_
((
options
&
MANY_ERRORS
)
!=
0
),
previous_name_
(
false
),
complete_
(
false
),
seen_error_
(
false
)
{}
...
...
@@ -101,6 +102,7 @@ public:
// Store the current status, so we can recover it upon popSource
include_info_
.
push_back
(
IncludeInfo
(
active_origin_
,
last_name_
));
initialized_
=
true
;
previous_name_
=
false
;
}
bool
popSource
()
{
...
...
@@ -117,6 +119,7 @@ public:
active_origin_
=
info
.
first
;
last_name_
=
info
.
second
;
include_info_
.
pop_back
();
previous_name_
=
false
;
return
(
true
);
}
...
...
@@ -238,6 +241,8 @@ private:
// in that file.
typedef
pair
<
Name
,
shared_ptr
<
Name
>
>
IncludeInfo
;
vector
<
IncludeInfo
>
include_info_
;
bool
previous_name_
;
// True if there was a previous name in this file
// (false at the beginning or after an $INCLUDE line)
public:
bool
complete_
;
// All work done.
bool
seen_error_
;
// Was there at least one error during the
...
...
@@ -312,11 +317,17 @@ MasterLoader::MasterLoaderImpl::loadIncremental(size_t count_limit) {
last_name_
.
reset
(
new
Name
(
name_string
.
beg
,
name_string
.
len
,
&
active_origin_
));
previous_name_
=
true
;
}
else
if
(
initial_token
.
getType
()
==
MasterToken
::
INITIAL_WS
)
{
// This means the same name as previous.
if
(
last_name_
.
get
()
==
NULL
)
{
isc_throw
(
InternalException
,
"No previous name to use in "
"place of initial whitespace"
);
}
else
if
(
!
previous_name_
)
{
callbacks_
.
warning
(
lexer_
.
getSourceName
(),
lexer_
.
getSourceLine
(),
"Ambiguous previous name previous name "
"for initial whitespace"
);
}
}
else
if
(
initial_token
.
getType
()
==
MasterToken
::
ERROR
)
{
// Error token here.
...
...
src/lib/dns/tests/master_loader_unittest.cc
View file @
471c6f2d
...
...
@@ -478,13 +478,32 @@ TEST_F(MasterLoaderTest, includeOriginRestore) {
// Successfully load the data
loader_
->
load
();
EXPECT_TRUE
(
loader_
->
loadedSucessfully
());
EXPECT_TRUE
(
errors_
.
empty
())
<<
errors_
[
0
]
;
EXPECT_TRUE
(
errors_
.
empty
());
EXPECT_TRUE
(
warnings_
.
empty
());
// And check it's the correct data
checkARR
(
"www.example.org"
);
checkARR
(
"example.org"
);
}
// Check we restore the last name for initial whitespace when returning from
// include. But we do produce a warning if there's one just ofter the include.
TEST_F
(
MasterLoaderTest
,
includeAndInitialWS
)
{
const
string
include_string
=
"xyz 1H IN A 192.0.2.1
\n
"
"$INCLUDE "
TEST_DATA_SRCDIR
"/example.org
\n
"
" 1H IN A 192.0.2.1
\n
"
;
stringstream
ss
(
include_string
);
setLoader
(
ss
,
Name
(
"example.org"
),
RRClass
::
IN
(),
MasterLoader
::
MANY_ERRORS
);
// Successfully load the data
loader_
->
load
();
EXPECT_TRUE
(
loader_
->
loadedSucessfully
());
EXPECT_TRUE
(
errors_
.
empty
());
EXPECT_EQ
(
1
,
warnings_
.
size
());
checkARR
(
"xyz.example.org"
);
checkBasicRRs
();
checkARR
(
"xyz.example.org"
);
}
// Test the constructor rejects empty add callback.
TEST_F
(
MasterLoaderTest
,
emptyCallback
)
{
EXPECT_THROW
(
MasterLoader
(
TEST_DATA_SRCDIR
"/example.org"
,
...
...
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