C and C++ Binaries


MISC.TIMEBOMB : Potential Timebomb

Summary

A system-generated time is compared to a value that is not a system-generated time (and thus may be tainted or otherwise suspicious). Such comparisons can potentially lead to time bombs: behavior that is intended to execute only at a specific relative or absolute time.

Properties

Class Name Potential Timebomb
Significance style
Mnemonic MISC.TIMEBOMB
Categories
MisraC2023 MisraC2023:21.10 The Standard Library time and date functions shall not be used
Misra2012 Misra2012:21.10 The Standard Library time and date functions shall not be used
Misra2004 Misra2004:20.12 The time handling functions of library <time.h> shall not be used
AUTOSARC++14 AUTOSARC++14:M18-0-4 The time handling functions of library <ctime> shall not be used.
MisraC++2008 MisraC++2008:18-0-4 The time handling functions of library <ctime> shall not be used.
CWE CWE:511 Logic/Time Bomb
Availability Available for C and C++.
Enabling Checks for this warning class are disabled by default, and it tracks 'time' taint which is also disabled by default. To enable the checks, make the following changes to the project configuration file.
  • Add the following rules.
    DISABLED_TAINT_KINDS =  
    WARNING_FILTER += allow class="Potential Timebomb"
    
    and,
  • For any taint kinds that you wish to disable (since the rule you just added enables all kinds), add a DISABLED_TAINT_KINDS+= rule after DISABLED_TAINT_KINDS="".

Example

#include <time.h>

void misc_timebomb(void){
    time_t deadline = 1893456000;
    time_t now = time(NULL);

    if (now > time(NULL)){               /* ok: time value compared against another time value */
        return;
    }

    if (now < deadline){ /* 'Potential Timebomb' warning issued: time value compared against non-time value */
        return;
    }

    /* An inside attacker could put malicious code here:
     * it would only be executed once the deadline was past. */
}

Functions that Generate System Times

CodeSonar ships with library models that allow it to recognize a functions such as libc mktime() and Win32 GetTickCount() that produce system time values by returning such values, writing them through an argument pointer, or both.

If you have created a custom library model for some function f() in terms of one of these existing models, calls to f() will also be treated as producing system time values under the same circumstances.

Relevant Configuration File Parameters

The following configuration file parameters affect checks for this warning class.