Section Subclause 7.27.3.1 of the C Standard [ISO/IEC 9899:2011] provides the following sample implementation of the asctime() function:
...
| Code Block | ||||
|---|---|---|---|---|
| ||||
#define __STDC_WANT_LIB_EXT1__ 1
#include <time.h>
void func(void) {
struct tm time_tm;
const size_t maxsize = 26; /* or maximum size of time string */;
char buffer[maxsize];
/* Initialize time_tm */
if (asctime_s(buffer, maxsize, &time_tm)) {
/* Handle error */
}
} |
...
| Code Block | ||||
|---|---|---|---|---|
| ||||
#include <time.h>
void func(void) {
struct tm time;
const size_t maxsize = 26; /* or maximum size of time string */;
char s[maxsize];
const char *format = "%c"; /* current time representation for locale */
const char *format = "%c";
const struct tm *timeptr;
size_t size = strftime(s, maxsize, format, timeptr);
} |
...
Rule | Severity | Likelihood | Remediation Cost | Priority | Level |
|---|---|---|---|---|---|
MSC33-C | highHigh | likelyLikely | lowLow | P27 | L1 |
Related Vulnerabilities
Search for vulnerabilities resulting from the violation of this rule on the CERT website.
Related Guidelines
Bibliography
| [ISO/IEC 9899:2011] | Section Subclause 7.27.3.1, "The asctime Function" |
| [Open Group 2008] | "asctime, asctime_r—Convert Date and Time to a String" |
...