diff options
author | Martin Willi <martin@revosec.ch> | 2013-10-15 16:10:05 +0200 |
---|---|---|
committer | Martin Willi <martin@revosec.ch> | 2014-06-04 15:52:58 +0200 |
commit | 8f129319ffd44f6e065a648283a77713c47b1d73 (patch) | |
tree | 781d34de5a4a8199d0dc84e7968ea8c8a292b6e4 | |
parent | 087e02e47ebddef0aaad7b0aa554418336cfc517 (diff) | |
download | strongswan-8f129319ffd44f6e065a648283a77713c47b1d73.tar.bz2 strongswan-8f129319ffd44f6e065a648283a77713c47b1d73.tar.xz |
utils: Printf() defined time output should gmtime/localtime_r() fail
-rw-r--r-- | src/libstrongswan/utils/utils.c | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/src/libstrongswan/utils/utils.c b/src/libstrongswan/utils/utils.c index 7cca845f7..fe3b32f6c 100644 --- a/src/libstrongswan/utils/utils.c +++ b/src/libstrongswan/utils/utils.c @@ -648,20 +648,23 @@ int time_printf_hook(printf_hook_data_t *data, printf_hook_spec_t *spec, }; time_t *time = *((time_t**)(args[0])); bool utc = *((int*)(args[1])); - struct tm t; + struct tm t, *ret = NULL; - if (*time == UNDEFINED_TIME) + if (*time != UNDEFINED_TIME) { - return print_in_hook(data, "--- -- --:--:--%s----", - utc ? " UTC " : " "); - } - if (utc) - { - gmtime_r(time, &t); + if (utc) + { + ret = gmtime_r(time, &t); + } + else + { + ret = localtime_r(time, &t); + } } - else + if (ret == NULL) { - localtime_r(time, &t); + return print_in_hook(data, "--- -- --:--:--%s----", + utc ? " UTC " : " "); } return print_in_hook(data, "%s %02d %02d:%02d:%02d%s%04d", months[t.tm_mon], t.tm_mday, t.tm_hour, t.tm_min, |