From 00c552fe2f77cbf9eaecc936d41209bb72ebf05d Mon Sep 17 00:00:00 2001 From: Ole Herman Schumacher Elgesem Date: Tue, 28 Aug 2018 11:08:52 -0700 Subject: [PATCH] Fixed error in gmtime example gmtime and gmtime_r take a time_t pointer, so have to store the value of time(NULL) on the stack. Signed-off-by: Ole Herman Schumacher Elgesem --- .../src/Security/CWE/CWE-676/PotentiallyDangerousFunction.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cpp/ql/src/Security/CWE/CWE-676/PotentiallyDangerousFunction.c b/cpp/ql/src/Security/CWE/CWE-676/PotentiallyDangerousFunction.c index d455bb102b0..87c2b32bc45 100644 --- a/cpp/ql/src/Security/CWE/CWE-676/PotentiallyDangerousFunction.c +++ b/cpp/ql/src/Security/CWE/CWE-676/PotentiallyDangerousFunction.c @@ -1,12 +1,14 @@ // BAD: using gmtime int is_morning_bad() { - struct tm *now = gmtime(time(NULL)); + const time_t now_seconds = time(NULL); + struct tm *now = gmtime(&now_seconds); return (now->tm_hour < 12); } // GOOD: using gmtime_r int is_morning_good() { + const time_t now_seconds = time(NULL); struct tm now; - gmtime_r(time(NULL), &now); + gmtime_r(&now_seconds, &now); return (now.tm_hour < 12); }