summaryrefslogtreecommitdiff
path: root/bin/dnssec/dnssectool.c
diff options
context:
space:
mode:
Diffstat (limited to 'bin/dnssec/dnssectool.c')
-rw-r--r--bin/dnssec/dnssectool.c41
1 files changed, 26 insertions, 15 deletions
diff --git a/bin/dnssec/dnssectool.c b/bin/dnssec/dnssectool.c
index 7c8c6ce2..5f5f7d88 100644
--- a/bin/dnssec/dnssectool.c
+++ b/bin/dnssec/dnssectool.c
@@ -319,11 +319,35 @@ strtotime(const char *str, isc_int64_t now, isc_int64_t base) {
isc_result_t result;
const char *orig = str;
char *endp;
+ int n;
if ((str[0] == '0' || str[0] == '-') && str[1] == '\0')
return ((isc_stdtime_t) 0);
- if (strncmp(str, "now", 3) == 0) {
+ /*
+ * We accept times in the following formats:
+ * now([+-]offset)
+ * YYYYMMDD([+-]offset)
+ * YYYYMMDDhhmmss([+-]offset)
+ * [+-]offset
+ */
+ n = strspn(str, "0123456789");
+ if ((n == 8 || n == 14) &&
+ (str[n] == '\0' || str[n] == '-' || str[n] == '+'))
+ {
+ char timestr[15];
+
+ strlcpy(timestr, str, sizeof(timestr));
+ timestr[n] = 0;
+ if (n == 8)
+ strlcat(timestr, "000000", sizeof(timestr));
+ result = dns_time64_fromtext(timestr, &val);
+ if (result != ISC_R_SUCCESS)
+ fatal("time value %s is invalid: %s", orig,
+ isc_result_totext(result));
+ base = val;
+ str += n;
+ } else if (strncmp(str, "now", 3) == 0) {
base = now;
str += 3;
}
@@ -338,21 +362,8 @@ strtotime(const char *str, isc_int64_t now, isc_int64_t base) {
offset = strtol(str + 1, &endp, 0);
offset = time_units((isc_stdtime_t) offset, endp, orig);
val = base - offset;
- } else if (strlen(str) == 8U) {
- char timestr[15];
- sprintf(timestr, "%s000000", str);
- result = dns_time64_fromtext(timestr, &val);
- if (result != ISC_R_SUCCESS)
- fatal("time value %s is invalid: %s", orig,
- isc_result_totext(result));
- } else if (strlen(str) > 14U) {
+ } else
fatal("time value %s is invalid", orig);
- } else {
- result = dns_time64_fromtext(str, &val);
- if (result != ISC_R_SUCCESS)
- fatal("time value %s is invalid: %s", orig,
- isc_result_totext(result));
- }
return ((isc_stdtime_t) val);
}