aboutsummaryrefslogtreecommitdiffstats
path: root/ui/gtk
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2016-10-21 19:18:15 -0700
committerGuy Harris <guy@alum.mit.edu>2016-10-22 02:27:32 +0000
commit10ca4c7527122efde0300205deaa6c0143f07219 (patch)
tree5352128043afff3b586c4a314ab2d240aec36f6a /ui/gtk
parent49cf42c571f3f94632957371ccd99533e71764ff (diff)
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 'ui/gtk')
-rw-r--r--ui/gtk/fileset_dlg.c20
-rw-r--r--ui/gtk/iax2_analysis.c23
-rw-r--r--ui/gtk/io_stat.c21
-rw-r--r--ui/gtk/main_welcome.c2
-rw-r--r--ui/gtk/memory_dlg.c21
-rw-r--r--ui/gtk/rtp_analysis.c22
-rw-r--r--ui/gtk/rtp_player.c10
7 files changed, 76 insertions, 43 deletions
diff --git a/ui/gtk/fileset_dlg.c b/ui/gtk/fileset_dlg.c
index bb0e04d7fe..cc28f2b152 100644
--- a/ui/gtk/fileset_dlg.c
+++ b/ui/gtk/fileset_dlg.c
@@ -160,15 +160,23 @@ fileset_dlg_add_file(fileset_entry *entry, void *window _U_) {
/* if this file doesn't follow the file set pattern, */
/* use the creation time of that file */
local = localtime(&entry->ctime);
- created = g_strdup_printf("%04u-%02u-%02u %02u:%02u:%02u",
- local->tm_year+1900, local->tm_mon+1, local->tm_mday,
- local->tm_hour, local->tm_min, local->tm_sec);
+ if (local != NULL) {
+ created = g_strdup_printf("%04u-%02u-%02u %02u:%02u:%02u",
+ local->tm_year+1900, local->tm_mon+1, local->tm_mday,
+ local->tm_hour, local->tm_min, local->tm_sec);
+ } else {
+ created = g_strdup("Time not representable");
+ }
}
local = localtime(&entry->mtime);
- modified = g_strdup_printf("%04u-%02u-%02u %02u:%02u:%02u",
- local->tm_year+1900, local->tm_mon+1, local->tm_mday,
- local->tm_hour, local->tm_min, local->tm_sec);
+ if (local != NULL) {
+ modified = g_strdup_printf("%04u-%02u-%02u %02u:%02u:%02u",
+ local->tm_year+1900, local->tm_mon+1, local->tm_mday,
+ local->tm_hour, local->tm_min, local->tm_sec);
+ } else {
+ modified = g_strdup("Time not representable");
+ }
size = g_strdup_printf("%" G_GINT64_MODIFIER "d Bytes", entry->size);
fs_rb = gtk_radio_button_new_with_label_from_widget(
diff --git a/ui/gtk/iax2_analysis.c b/ui/gtk/iax2_analysis.c
index f8b45d1c75..d4ade50f23 100644
--- a/ui/gtk/iax2_analysis.c
+++ b/ui/gtk/iax2_analysis.c
@@ -516,14 +516,21 @@ static int iax2_packet_add_info(GtkWidget *list, user_data_t * user_data,
then = pinfo->abs_ts.secs;
msecs = (guint16)(pinfo->abs_ts.nsecs/1000000);
tm_tmp = localtime(&then);
- g_snprintf(timeStr,sizeof(timeStr),"%02d/%02d/%04d %02d:%02d:%02d.%03d",
- tm_tmp->tm_mon + 1,
- tm_tmp->tm_mday,
- tm_tmp->tm_year + 1900,
- tm_tmp->tm_hour,
- tm_tmp->tm_min,
- tm_tmp->tm_sec,
- msecs);
+ if (tm_tmp != NULL) {
+ /*
+ * XXX - somewhat US-centric here.
+ */
+ g_snprintf(timeStr,sizeof(timeStr),"%02d/%02d/%04d %02d:%02d:%02d.%03d",
+ tm_tmp->tm_mon + 1,
+ tm_tmp->tm_mday,
+ tm_tmp->tm_year + 1900,
+ tm_tmp->tm_hour,
+ tm_tmp->tm_min,
+ tm_tmp->tm_sec,
+ msecs);
+ } else {
+ g_snprintf(timeStr,sizeof(timeStr),"XX/XX/XXXX XX:XX:XX.XXX",
+ }
/* Default to using black on white text if nothing below overrides it */
g_snprintf(color_str,sizeof(color_str),"#ffffffffffff");
diff --git a/ui/gtk/io_stat.c b/ui/gtk/io_stat.c
index 7f3f4eee7c..2f16332506 100644
--- a/ui/gtk/io_stat.c
+++ b/ui/gtk/io_stat.c
@@ -488,15 +488,18 @@ print_interval_string(char *buf, int buf_len, guint32 interval, io_stat_t *io,
nsec_val -= 1000;
}
tmp = localtime (&sec_val);
- if (io->interval >= 1000) {
- g_snprintf(buf, buf_len, "%02d:%02d:%02d", tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
- } else if (io->interval >= 100) {
- g_snprintf(buf, buf_len, "%02d:%02d:%02d.%1d", tmp->tm_hour, tmp->tm_min, tmp->tm_sec, nsec_val/100);
- } else if (io->interval >= 10) {
- g_snprintf(buf, buf_len, "%02d:%02d:%02d.%02d", tmp->tm_hour, tmp->tm_min, tmp->tm_sec, nsec_val/10);
- } else {
- g_snprintf(buf, buf_len, "%02d:%02d:%02d.%03d", tmp->tm_hour, tmp->tm_min, tmp->tm_sec, nsec_val);
- }
+ if (tmp != NULL) {
+ if (io->interval >= 1000) {
+ g_snprintf(buf, buf_len, "%02d:%02d:%02d", tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
+ } else if (io->interval >= 100) {
+ g_snprintf(buf, buf_len, "%02d:%02d:%02d.%1d", tmp->tm_hour, tmp->tm_min, tmp->tm_sec, nsec_val/100);
+ } else if (io->interval >= 10) {
+ g_snprintf(buf, buf_len, "%02d:%02d:%02d.%02d", tmp->tm_hour, tmp->tm_min, tmp->tm_sec, nsec_val/10);
+ } else {
+ g_snprintf(buf, buf_len, "%02d:%02d:%02d.%03d", tmp->tm_hour, tmp->tm_min, tmp->tm_sec, nsec_val);
+ }
+ } else
+ g_snprintf(buf, buf_len, "Time not representable");
} else {
if (!ext) {
g_snprintf(buf, buf_len, "%d.%03d", interval/1000,interval%1000);
diff --git a/ui/gtk/main_welcome.c b/ui/gtk/main_welcome.c
index 696446f7b4..5debeb0fa0 100644
--- a/ui/gtk/main_welcome.c
+++ b/ui/gtk/main_welcome.c
@@ -330,7 +330,7 @@ welcome_header_set_message(gchar *msg) {
if (msg) {
g_string_append(message, msg);
} else { /* Use our default header */
- if ((now->tm_mon == 3 && now->tm_mday == 1) || (now->tm_mon == 6 && now->tm_mday == 14)) {
+ if (now != NULL && ((now->tm_mon == 3 && now->tm_mday == 1) || (now->tm_mon == 6 && now->tm_mday == 14))) {
g_string_append(message, "Sniffing the glue that holds the Internet together");
} else {
g_string_append(message, prefs.gui_start_title);
diff --git a/ui/gtk/memory_dlg.c b/ui/gtk/memory_dlg.c
index af06667076..d11122c2ae 100644
--- a/ui/gtk/memory_dlg.c
+++ b/ui/gtk/memory_dlg.c
@@ -130,15 +130,18 @@ print_interval_string(char *buf, int buf_len, guint32 interval, io_stat_t *io)
nsec_val -= 1000;
}
tmp = localtime (&sec_val);
- if (INTERVAL >= 1000) {
- g_snprintf(buf, buf_len, "%02d:%02d:%02d", tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
- } else if (INTERVAL >= 100) {
- g_snprintf(buf, buf_len, "%02d:%02d:%02d.%1d", tmp->tm_hour, tmp->tm_min, tmp->tm_sec, nsec_val/100);
- } else if (INTERVAL >= 10) {
- g_snprintf(buf, buf_len, "%02d:%02d:%02d.%02d", tmp->tm_hour, tmp->tm_min, tmp->tm_sec, nsec_val/10);
- } else {
- g_snprintf(buf, buf_len, "%02d:%02d:%02d.%03d", tmp->tm_hour, tmp->tm_min, tmp->tm_sec, nsec_val);
- }
+ if (tmp != NULL) {
+ if (INTERVAL >= 1000) {
+ g_snprintf(buf, buf_len, "%02d:%02d:%02d", tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
+ } else if (INTERVAL >= 100) {
+ g_snprintf(buf, buf_len, "%02d:%02d:%02d.%1d", tmp->tm_hour, tmp->tm_min, tmp->tm_sec, nsec_val/100);
+ } else if (INTERVAL >= 10) {
+ g_snprintf(buf, buf_len, "%02d:%02d:%02d.%02d", tmp->tm_hour, tmp->tm_min, tmp->tm_sec, nsec_val/10);
+ } else {
+ g_snprintf(buf, buf_len, "%02d:%02d:%02d.%03d", tmp->tm_hour, tmp->tm_min, tmp->tm_sec, nsec_val);
+ }
+ } else
+ g_snprintf(buf, buf_len, "XX:XX:XX");
}
static void
diff --git a/ui/gtk/rtp_analysis.c b/ui/gtk/rtp_analysis.c
index 239f8569da..0089624909 100644
--- a/ui/gtk/rtp_analysis.c
+++ b/ui/gtk/rtp_analysis.c
@@ -570,14 +570,20 @@ rtp_packet_add_info(GtkWidget *list, user_data_t * user_data,
then = pinfo->abs_ts.secs;
msecs = (guint16)(pinfo->abs_ts.nsecs/1000000);
tm_tmp = localtime(&then);
- g_snprintf(timeStr, sizeof(timeStr), "%02d/%02d/%04d %02d:%02d:%02d.%03d",
- tm_tmp->tm_mon + 1,
- tm_tmp->tm_mday,
- tm_tmp->tm_year + 1900,
- tm_tmp->tm_hour,
- tm_tmp->tm_min,
- tm_tmp->tm_sec,
- msecs);
+ if (tm_tmp != NULL) {
+ /*
+ * XXX - somewhat US-centric.
+ */
+ g_snprintf(timeStr, sizeof(timeStr), "%02d/%02d/%04d %02d:%02d:%02d.%03d",
+ tm_tmp->tm_mon + 1,
+ tm_tmp->tm_mday,
+ tm_tmp->tm_year + 1900,
+ tm_tmp->tm_hour,
+ tm_tmp->tm_min,
+ tm_tmp->tm_sec,
+ msecs);
+ } else
+ g_snprintf(timeStr, sizeof(timeStr), "XX/XX/XXXX XX:XX:XX.XXX");
/* Default to using black on white text if nothing below overrides it */
g_snprintf(color_str, sizeof(color_str), "#ffffffffffff");
diff --git a/ui/gtk/rtp_player.c b/ui/gtk/rtp_player.c
index 7d051093ad..aaa029a51e 100644
--- a/ui/gtk/rtp_player.c
+++ b/ui/gtk/rtp_player.c
@@ -1303,7 +1303,10 @@ channel_draw(rtp_channel_info_t *rci)
if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(cb_view_as_time_of_day))) {
seconds = rci->start_time_abs.secs + i * MULT / sample_rate;
timestamp = localtime(&seconds);
- g_snprintf(label_string, MAX_TIME_LABEL, "%02d:%02d:%02d", timestamp->tm_hour, timestamp->tm_min, timestamp->tm_sec);
+ if (timestamp != NULL
+ g_snprintf(label_string, MAX_TIME_LABEL, "%02d:%02d:%02d", timestamp->tm_hour, timestamp->tm_min, timestamp->tm_sec);
+ else
+ g_snprintf(label_string, MAX_TIME_LABEL, "XX:XX:XX");
} else {
g_snprintf(label_string, MAX_TIME_LABEL, "%.0f s", floor(nstime_to_sec(&rci->start_time_abs)) + i*MULT/sample_rate);
}
@@ -1451,7 +1454,10 @@ channel_draw(rtp_channel_info_t *rci)
if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(cb_view_as_time_of_day))) {
seconds = rci->start_time_abs.secs + i * MULT / sample_rate;
timestamp = localtime(&seconds);
- g_snprintf(label_string, MAX_TIME_LABEL, "%02d:%02d:%02d", timestamp->tm_hour, timestamp->tm_min, timestamp->tm_sec);
+ if (timestamp != NULL)
+ g_snprintf(label_string, MAX_TIME_LABEL, "%02d:%02d:%02d", timestamp->tm_hour, timestamp->tm_min, timestamp->tm_sec);
+ else
+ g_snprintf(label_string, MAX_TIME_LABEL, "XX:XX:XX");
} else {
g_snprintf(label_string, MAX_TIME_LABEL, "%.0f s", floor(nstime_to_sec(&rci->start_time_abs)) + i*MULT/sample_rate);
}