summaryrefslogtreecommitdiff
path: root/epan/print.c
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 /epan/print.c
parent49cf42c571f3f94632957371ccd99533e71764ff (diff)
downloadwireshark-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 'epan/print.c')
-rw-r--r--epan/print.c21
1 files changed, 17 insertions, 4 deletions
diff --git a/epan/print.c b/epan/print.c
index 3ae96f5a0c..a54d84873a 100644
--- a/epan/print.c
+++ b/epan/print.c
@@ -246,9 +246,16 @@ void
write_pdml_preamble(FILE *fh, const gchar *filename)
{
time_t t = time(NULL);
- char *ts = asctime(localtime(&t));
+ struct tm * timeinfo;
+ char *ts;
- ts[strlen(ts)-1] = 0; /* overwrite \n */
+ /* Create the output */
+ timeinfo = localtime(&t);
+ if (timeinfo != NULL) {
+ ts = asctime(timeinfo);
+ ts[strlen(ts)-1] = 0; /* overwrite \n */
+ } else
+ ts = "Not representable";
fprintf(fh, "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
fprintf(fh, "<?xml-stylesheet type=\"text/xsl\" href=\"" PDML2HTML_XSL "\"?>\n");
@@ -333,7 +340,10 @@ write_json_proto_tree(output_fields_t* fields, print_args_t *print_args, gchar *
/* Create the output */
timeinfo = localtime(&t);
- strftime(ts, 30, "%Y-%m-%d", timeinfo);
+ if (timeinfo != NULL)
+ strftime(ts, sizeof ts, "%Y-%m-%d", timeinfo);
+ else
+ g_strlcpy(ts, "XXXX-XX-XX", sizeof ts); /* XXX - better way of saying "Not representable"? */
if (!is_first)
fputs(" ,\n", fh);
@@ -381,7 +391,10 @@ write_ek_proto_tree(output_fields_t* fields, print_args_t *print_args, gchar **p
/* Create the output */
timeinfo = localtime(&t);
- strftime(ts, 30, "%Y-%m-%d", timeinfo);
+ if (timeinfo != NULL)
+ strftime(ts, sizeof ts, "%Y-%m-%d", timeinfo);
+ else
+ g_strlcpy(ts, "XXXX-XX-XX", sizeof ts); /* XXX - better way of saying "Not representable"? */
fprintf(fh, "{\"index\" : {\"_index\": \"packets-%s\", \"_type\": \"pcap_file\", \"_score\": null}}\n", ts);
/* Timestamp added for time indexing in Elasticsearch */