Browse Source

- in the fromText function, check string length before sscanf(),
and use DATE_LEN enum instead of hard-coding the value 14


git-svn-id: svn://bind10.isc.org/svn/bind10/trunk@1030 e5f2f494-b856-4b98-b285-d166d9295462

Evan Hunt 15 years ago
parent
commit
c3c47b30cf
1 changed files with 8 additions and 2 deletions
  1. 8 2
      src/lib/dns/cpp/dnstime.cc

+ 8 - 2
src/lib/dns/cpp/dnstime.cc

@@ -40,6 +40,10 @@ using namespace std;
 namespace isc {
 namespace dns {
 
+enum {
+    DATE_LEN = 14       // YYYYMMDDHHmmSS
+};
+
 string
 DNSSECTimeToText(const time_t timeval)
 {
@@ -80,8 +84,10 @@ DNSSECTimeFromText(const string& time_txt)
 
     // first try reading YYYYMMDDHHmmSS format
     int year, month, day, hour, minute, second;
-    if (sscanf(time_txt.c_str(), "%4d%2d%2d%2d%2d%2d",
-               &year, &month, &day, &hour, &minute, &second) != 6) {
+    if (time_txt.length() != DATE_LEN ||
+        sscanf(time_txt.c_str(), "%4d%2d%2d%2d%2d%2d",
+               &year, &month, &day, &hour, &minute, &second) != 6)
+    {
         ostringstream oss;
         oss << "Couldn't convert time value: " << time_txt;
         dns_throw(InvalidTime, oss.str().c_str());