[metadata]
id = "MSC33-C"
type = "rule"
category = "MSC"
number = 33
title = "Do not pass invalid data to the asctime() function"
description = """
The C Standard, 7.29.3.1 [ISO/IEC 9899:2024], provides the following sample
implementation of theasctime()function: char *asctime(const struct tm *timeptr)
{ static const char wday_name[7][3] = { "Sun", "Mon", "Tue", "Wed", "Thu",
"Fri", "Sat" }; static const char mon_name[12][3] = { "Jan", "Feb", "Mar",
"Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; static char
result[26]; sprintf( result, "%.3s %.3s%3d %.2d:%.2d:%.2d %d\n",
wday_name[timeptr->tm_wday], mon_name[timeptr->tm_mon], timeptr->tm_mday,
timeptr->tm_hour, timeptr->tm_min, timeptr->tm_sec, 1900 + timeptr->tm_year );
return result; } This function is supposed to output a character string of 26
characters at most, including the terminating null character. If we count the
length indicated by the format directives, we arrive at 25. Taking into account
the terminating null character, the array size of the string appears sufficient.
"""
severity = "High"
likelihood = "Likely"
priority = "P9"
level = "L2"
cert_version = "2016 Edition (Wiki)"
last_modified = "Oct 31, 2025"
[rules.cert_c.MSC33-C]
enabled = true
[references]
wiki = "https://wiki.sei.cmu.edu/confluence/display/c/MSC33-C.+Do+not+pass+invalid+data+to+the+asctime%28%29+function"