diff options
author | Guy Harris <guy@alum.mit.edu> | 2016-10-21 19:18:15 -0700 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2016-10-22 02:27:32 +0000 |
commit | 10ca4c7527122efde0300205deaa6c0143f07219 (patch) | |
tree | 5352128043afff3b586c4a314ab2d240aec36f6a /wiretap/logcat_text.c | |
parent | 49cf42c571f3f94632957371ccd99533e71764ff (diff) | |
download | wireshark-10ca4c7527122efde0300205deaa6c0143f07219.tar.gz |
More checks for localtime() and gmtime() returning NULL.
And some comments in the case where we're converting the result of
time() - if your machine's idea of time predates January 1, 1970,
00:00:00 UTC, it'll crash on Windows, but that's not a case where a
*file* can cause the problem due either to a bad file time stamp or bad
time stamps in the file.
Change-Id: I837a438e4b875dd8c4f3ec2137df7a16ee4e9498
Reviewed-on: https://code.wireshark.org/review/18369
Reviewed-by: Guy Harris <guy@alum.mit.edu>
Diffstat (limited to 'wiretap/logcat_text.c')
-rw-r--r-- | wiretap/logcat_text.c | 43 |
1 files changed, 31 insertions, 12 deletions
diff --git a/wiretap/logcat_text.c b/wiretap/logcat_text.c index 551358170f..2f7e5bc294 100644 --- a/wiretap/logcat_text.c +++ b/wiretap/logcat_text.c @@ -104,6 +104,7 @@ static gchar *logcat_log(const struct dumper_t *dumper, guint32 seconds, { gchar time_buffer[15]; time_t datetime; + struct tm *tm; datetime = (time_t) seconds; @@ -123,20 +124,38 @@ static gchar *logcat_log(const struct dumper_t *dumper, guint32 seconds, return g_strdup_printf("%c(%5i:%5i) %s\n", priority, pid, tid, log); case WTAP_ENCAP_LOGCAT_TIME: - strftime(time_buffer, sizeof(time_buffer), "%m-%d %H:%M:%S", - gmtime(&datetime)); - return g_strdup_printf("%s.%03i %c/%-8s(%5i): %s\n", - time_buffer, milliseconds, priority, tag, pid, log); + tm = gmtime(&datetime); + if (tm != NULL) { + strftime(time_buffer, sizeof(time_buffer), "%m-%d %H:%M:%S", + tm); + return g_strdup_printf("%s.%03i %c/%-8s(%5i): %s\n", + time_buffer, milliseconds, priority, tag, pid, log); + } else { + return g_strdup_printf("Not representable %c/%-8s(%5i): %s\n", + priority, tag, pid, log); + } case WTAP_ENCAP_LOGCAT_THREADTIME: - strftime(time_buffer, sizeof(time_buffer), "%m-%d %H:%M:%S", - gmtime(&datetime)); - return g_strdup_printf("%s.%03i %5i %5i %c %-8s: %s\n", - time_buffer, milliseconds, pid, tid, priority, tag, log); + tm = gmtime(&datetime); + if (tm != NULL) { + strftime(time_buffer, sizeof(time_buffer), "%m-%d %H:%M:%S", + tm); + return g_strdup_printf("%s.%03i %5i %5i %c %-8s: %s\n", + time_buffer, milliseconds, pid, tid, priority, tag, log); + } else { + return g_strdup_printf("Not representable %5i %5i %c %-8s: %s\n", + pid, tid, priority, tag, log); + } case WTAP_ENCAP_LOGCAT_LONG: - strftime(time_buffer, sizeof(time_buffer), "%m-%d %H:%M:%S", - gmtime(&datetime)); - return g_strdup_printf("[ %s.%03i %5i:%5i %c/%-8s ]\n%s\n\n", - time_buffer, milliseconds, pid, tid, priority, tag, log); + tm = gmtime(&datetime); + if (tm != NULL) { + strftime(time_buffer, sizeof(time_buffer), "%m-%d %H:%M:%S", + tm); + return g_strdup_printf("[ %s.%03i %5i:%5i %c/%-8s ]\n%s\n\n", + time_buffer, milliseconds, pid, tid, priority, tag, log); + } else { + return g_strdup_printf("[ Not representable %5i:%5i %c/%-8s ]\n%s\n\n", + pid, tid, priority, tag, log); + } default: return NULL; } |