Skip to content
Snippets Groups Projects
Commit a241e39e authored by Jan Včelák's avatar Jan Včelák :rocket:
Browse files

dnssec, fix parsing key timestamps in strict POSIX environment

parent 84fdb756
No related branches found
No related tags found
1 merge request!421DNSSEC, key time stamps parsing
......@@ -23,9 +23,7 @@
#include "key.h"
#include "shared.h"
#include "strtonum.h"
// ISO 8610
#define TIME_FORMAT "%Y-%m-%dT%H:%M:%S%z"
#include "timestamp.h"
int decode_ignore(_unused_ const json_t *value, _unused_ void *result)
{
......@@ -279,14 +277,10 @@ int decode_time(const json_t *value, void *result)
}
const char *time_str = json_string_value(value);
struct tm tm = { 0 };
char *end = strptime(time_str, TIME_FORMAT, &tm);
if (end == NULL || *end != '\0') {
if (!timestamp_read(time_str, time_ptr)) {
return DNSSEC_CONFIG_MALFORMED;
}
*time_ptr = timegm(&tm);
return DNSSEC_EOK;
}
......@@ -302,14 +296,8 @@ int encode_time(const void *value, json_t **result)
return DNSSEC_EOK;
}
struct tm tm = { 0 };
if (!gmtime_r(time_ptr, &tm)) {
return DNSSEC_CONFIG_MALFORMED;
}
char buffer[128] = { 0 };
int written = strftime(buffer, sizeof(buffer), TIME_FORMAT, &tm);
if (written == 0) {
if (!timestamp_write(buffer, sizeof(buffer), *time_ptr)) {
return DNSSEC_CONFIG_MALFORMED;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment