From 6297f11724e4da2706920242223381d91a11ea27 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Wed, 27 Jan 2016 09:39:58 -0800 Subject: [PATCH] GUAC-1452: Cap timing entries at a maximum of 24 hours per entry. --- src/terminal/typescript.c | 8 +++++--- src/terminal/typescript.h | 7 +++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/terminal/typescript.c b/src/terminal/typescript.c index 3b8790b1..2460cadb 100644 --- a/src/terminal/typescript.c +++ b/src/terminal/typescript.c @@ -98,13 +98,15 @@ void guac_terminal_typescript_flush(guac_terminal_typescript* typescript) { guac_timestamp this_flush = guac_timestamp_current(); guac_timestamp last_flush = typescript->last_flush; - /* Calculate elapsed time in seconds */ - double elapsed_time = (this_flush - last_flush) / 1000.0; + /* Calculate time since last flush */ + int elapsed_time = this_flush - last_flush; + if (elapsed_time > GUAC_TERMINAL_TYPESCRIPT_MAX_DELAY) + elapsed_time = GUAC_TERMINAL_TYPESCRIPT_MAX_DELAY; /* Produce single line of timestamp output */ char timestamp_buffer[32]; int timestamp_length = snprintf(timestamp_buffer, sizeof(timestamp_buffer), - "%0.6f %i\n", elapsed_time, typescript->length); + "%0.6f %i\n", elapsed_time / 1000.0, typescript->length); /* Calculate actual length of timestamp line */ if (timestamp_length > sizeof(timestamp_buffer)) diff --git a/src/terminal/typescript.h b/src/terminal/typescript.h index 172a71c8..b6bba80f 100644 --- a/src/terminal/typescript.h +++ b/src/terminal/typescript.h @@ -40,6 +40,13 @@ */ #define GUAC_TERMINAL_TYPESCRIPT_FOOTER "\n[END TYPESCRIPT]\n" +/** + * The maximum amount of time to allow for a particular timing entry, in + * milliseconds. Any timing entries exceeding this value will be written as + * exactly this value instead. + */ +#define GUAC_TERMINAL_TYPESCRIPT_MAX_DELAY 86400000 + /** * An active typescript, consisting of a data file (raw terminal output) and * timing file (related timestamps and byte counts).