BIND 10 trac929, updated. 330dd7915a9a6b808db7b65b236e733e42401b8d [trac930] consideration for buffer overflow - use std::vector<char> instead of char[] - use strncmp() instead of strcmp() - shorten length of char array for the buffer (not directly related to buffer overflow)
BIND 10 source code commits
bind10-changes at lists.isc.org
Tue Aug 9 04:30:36 UTC 2011
The branch, trac929 has been updated
via 330dd7915a9a6b808db7b65b236e733e42401b8d (commit)
from e9620e0d9dd3d967bcfb99562f13848c70538a44 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 330dd7915a9a6b808db7b65b236e733e42401b8d
Author: Naoki Kambe <kambe at jprs.co.jp>
Date: Tue Aug 9 12:27:32 2011 +0900
[trac930]
consideration for buffer overflow
- use std::vector<char> instead of char[]
- use strncmp() instead of strcmp()
- shorten length of char array for the buffer
(not directly related to buffer overflow)
add more unittests for some wrong type formats into both c++ and python codes
(unittests for the previous change git e9620e0d9dd3d967bcfb99562f13848c70538a44)
- date-time-type format not ending with "Z"
- date-type format ending with "T"
- time-type format ending with "Z"
-----------------------------------------------------------------------
Summary of changes:
src/lib/config/module_spec.cc | 8 ++++----
src/lib/config/tests/module_spec_unittests.cc | 13 +++++++++++++
.../python/isc/config/tests/module_spec_test.py | 6 ++++++
3 files changed, 23 insertions(+), 4 deletions(-)
-----------------------------------------------------------------------
diff --git a/src/lib/config/module_spec.cc b/src/lib/config/module_spec.cc
index 27cf993..bebe695 100644
--- a/src/lib/config/module_spec.cc
+++ b/src/lib/config/module_spec.cc
@@ -103,15 +103,15 @@ check_format(ConstElementPtr value, ConstElementPtr format_name) {
BOOST_FOREACH (const format_types::value_type& f, time_formats) {
if (format_name->stringValue() == f.first) {
struct tm tm;
- char buf[255] = "";
+ std::vector<char> buf(32);
memset(&tm, 0, sizeof(tm));
// reverse check
return (strptime(value->stringValue().c_str(),
f.second.c_str(), &tm) != NULL
- && strftime(buf, sizeof(buf),
+ && strftime(&buf[0], buf.size(),
f.second.c_str(), &tm) != 0
- && strcmp(value->stringValue().c_str(),
- buf) == 0);
+ && strncmp(value->stringValue().c_str(),
+ &buf[0], buf.size()) == 0);
}
}
return (false);
diff --git a/src/lib/config/tests/module_spec_unittests.cc b/src/lib/config/tests/module_spec_unittests.cc
index cfd0ff5..b2ca7b4 100644
--- a/src/lib/config/tests/module_spec_unittests.cc
+++ b/src/lib/config/tests/module_spec_unittests.cc
@@ -358,6 +358,19 @@ TEST(ModuleSpec, CheckFormat) {
item_format = "\"item_format\": \"time\"";
specs.push_back("," + item_default + item_format);
+ // wrong date-time-type format not ending with "Z"
+ item_default = "\"item_default\": \"2011-05-27T19:42:57\",";
+ item_format = "\"item_format\": \"date-time\"";
+ specs.push_back("," + item_default + item_format);
+ // wrong date-type format ending with "T"
+ item_default = "\"item_default\": \"2011-05-27T\",";
+ item_format = "\"item_format\": \"date\"";
+ specs.push_back("," + item_default + item_format);
+ // wrong time-type format ending with "Z"
+ item_default = "\"item_default\": \"19:42:57Z\",";
+ item_format = "\"item_format\": \"time\"";
+ specs.push_back("," + item_default + item_format);
+
BOOST_FOREACH(std::string s, specs) {
el = Element::fromJSON(json_begin + s + json_end)->get("module_spec");
EXPECT_THROW(ModuleSpec(el, true), ModuleSpecError);
diff --git a/src/lib/python/isc/config/tests/module_spec_test.py b/src/lib/python/isc/config/tests/module_spec_test.py
index 567cfd4..fc53d23 100644
--- a/src/lib/python/isc/config/tests/module_spec_test.py
+++ b/src/lib/python/isc/config/tests/module_spec_test.py
@@ -352,6 +352,12 @@ class TestModuleSpec(unittest.TestCase):
self.assertFalse(isc.config.module_spec._check_format('', 'date-time'))
self.assertFalse(isc.config.module_spec._check_format(None, 'date-time'))
self.assertFalse(isc.config.module_spec._check_format(None, None))
+ # wrong date-time-type format not ending with "Z"
+ self.assertFalse(isc.config.module_spec._check_format('2011-05-27T19:42:57', 'date-time'))
+ # wrong date-type format ending with "T"
+ self.assertFalse(isc.config.module_spec._check_format('2011-05-27T', 'date'))
+ # wrong time-type format ending with "Z"
+ self.assertFalse(isc.config.module_spec._check_format('19:42:57Z', 'time'))
def test_validate_type(self):
errors = []
More information about the bind10-changes
mailing list