BIND 10 trac929, updated. e9620e0d9dd3d967bcfb99562f13848c70538a44 [trac929] add more strict check for date and time format (add reverse check)

BIND 10 source code commits bind10-changes at lists.isc.org
Fri Aug 5 07:43:40 UTC 2011


The branch, trac929 has been updated
       via  e9620e0d9dd3d967bcfb99562f13848c70538a44 (commit)
      from  4424c780b981979ec4e65ba96dd9da68fb0a1005 (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 e9620e0d9dd3d967bcfb99562f13848c70538a44
Author: Naoki Kambe <kambe at jprs.co.jp>
Date:   Fri Aug 5 14:22:28 2011 +0900

    [trac929] add more strict check for date and time format (add reverse check)

-----------------------------------------------------------------------

Summary of changes:
 src/lib/config/module_spec.cc                 |    9 ++++++++-
 src/lib/config/tests/module_spec_unittests.cc |    2 +-
 src/lib/python/isc/config/module_spec.py      |    6 ++++--
 3 files changed, 13 insertions(+), 4 deletions(-)

-----------------------------------------------------------------------
diff --git a/src/lib/config/module_spec.cc b/src/lib/config/module_spec.cc
index eed6b72..27cf993 100644
--- a/src/lib/config/module_spec.cc
+++ b/src/lib/config/module_spec.cc
@@ -103,8 +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] = "";
+            memset(&tm, 0, sizeof(tm));
+            // reverse check
             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);
diff --git a/src/lib/config/tests/module_spec_unittests.cc b/src/lib/config/tests/module_spec_unittests.cc
index 315a78d..cfd0ff5 100644
--- a/src/lib/config/tests/module_spec_unittests.cc
+++ b/src/lib/config/tests/module_spec_unittests.cc
@@ -287,7 +287,7 @@ TEST(ModuleSpec, CheckFormat) {
     item_default = "\"item_default\": \"2011-05-27\",";
     item_format  = "\"item_format\": \"date\"";
     specs.push_back("," + item_default + item_format);
-    item_default = "\"item_default\": \"19:42:57Z\",";
+    item_default = "\"item_default\": \"19:42:57\",";
     item_format  = "\"item_format\": \"time\"";
     specs.push_back("," + item_default + item_format);
 
diff --git a/src/lib/python/isc/config/module_spec.py b/src/lib/python/isc/config/module_spec.py
index d120080..b79f928 100644
--- a/src/lib/python/isc/config/module_spec.py
+++ b/src/lib/python/isc/config/module_spec.py
@@ -330,8 +330,10 @@ def _check_format(value, format_name):
     for fmt in time_formats:
         if format_name == fmt:
             try:
-                time.strptime(value, time_formats[fmt])
-                return True
+                # reverse check
+                return value == time.strftime(
+                    time_formats[fmt],
+                    time.strptime(value, time_formats[fmt]))
             except (ValueError, TypeError):
                 break
     return False




More information about the bind10-changes mailing list