Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Kea
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
Operations
Operations
Incidents
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Sebastian Schrader
Kea
Commits
93a7f7d1
Commit
93a7f7d1
authored
Aug 05, 2011
by
Naoki Kambe
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[trac929] add more strict check for date and time format (add reverse check)
parent
87e410c0
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
13 additions
and
4 deletions
+13
-4
src/lib/config/module_spec.cc
src/lib/config/module_spec.cc
+8
-1
src/lib/config/tests/module_spec_unittests.cc
src/lib/config/tests/module_spec_unittests.cc
+1
-1
src/lib/python/isc/config/module_spec.py
src/lib/python/isc/config/module_spec.py
+4
-2
No files found.
src/lib/config/module_spec.cc
View file @
93a7f7d1
...
@@ -103,8 +103,15 @@ check_format(ConstElementPtr value, ConstElementPtr format_name) {
...
@@ -103,8 +103,15 @@ check_format(ConstElementPtr value, ConstElementPtr format_name) {
BOOST_FOREACH
(
const
format_types
::
value_type
&
f
,
time_formats
)
{
BOOST_FOREACH
(
const
format_types
::
value_type
&
f
,
time_formats
)
{
if
(
format_name
->
stringValue
()
==
f
.
first
)
{
if
(
format_name
->
stringValue
()
==
f
.
first
)
{
struct
tm
tm
;
struct
tm
tm
;
char
buf
[
255
]
=
""
;
memset
(
&
tm
,
0
,
sizeof
(
tm
));
// reverse check
return
(
strptime
(
value
->
stringValue
().
c_str
(),
return
(
strptime
(
value
->
stringValue
().
c_str
(),
f
.
second
.
c_str
(),
&
tm
)
!=
NULL
);
f
.
second
.
c_str
(),
&
tm
)
!=
NULL
&&
strftime
(
buf
,
sizeof
(
buf
),
f
.
second
.
c_str
(),
&
tm
)
!=
0
&&
strcmp
(
value
->
stringValue
().
c_str
(),
buf
)
==
0
);
}
}
}
}
return
(
false
);
return
(
false
);
...
...
src/lib/config/tests/module_spec_unittests.cc
View file @
93a7f7d1
...
@@ -287,7 +287,7 @@ TEST(ModuleSpec, CheckFormat) {
...
@@ -287,7 +287,7 @@ TEST(ModuleSpec, CheckFormat) {
item_default
=
"
\"
item_default
\"
:
\"
2011-05-27
\"
,"
;
item_default
=
"
\"
item_default
\"
:
\"
2011-05-27
\"
,"
;
item_format
=
"
\"
item_format
\"
:
\"
date
\"
"
;
item_format
=
"
\"
item_format
\"
:
\"
date
\"
"
;
specs
.
push_back
(
","
+
item_default
+
item_format
);
specs
.
push_back
(
","
+
item_default
+
item_format
);
item_default
=
"
\"
item_default
\"
:
\"
19:42:57
Z
\"
,"
;
item_default
=
"
\"
item_default
\"
:
\"
19:42:57
\"
,"
;
item_format
=
"
\"
item_format
\"
:
\"
time
\"
"
;
item_format
=
"
\"
item_format
\"
:
\"
time
\"
"
;
specs
.
push_back
(
","
+
item_default
+
item_format
);
specs
.
push_back
(
","
+
item_default
+
item_format
);
...
...
src/lib/python/isc/config/module_spec.py
View file @
93a7f7d1
...
@@ -330,8 +330,10 @@ def _check_format(value, format_name):
...
@@ -330,8 +330,10 @@ def _check_format(value, format_name):
for
fmt
in
time_formats
:
for
fmt
in
time_formats
:
if
format_name
==
fmt
:
if
format_name
==
fmt
:
try
:
try
:
time
.
strptime
(
value
,
time_formats
[
fmt
])
# reverse check
return
True
return
value
==
time
.
strftime
(
time_formats
[
fmt
],
time
.
strptime
(
value
,
time_formats
[
fmt
]))
except
(
ValueError
,
TypeError
):
except
(
ValueError
,
TypeError
):
break
break
return
False
return
False
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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