Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

asctime_r: add param check to asctime_r() #8292

Merged
merged 1 commit into from Jan 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 15 additions & 0 deletions libs/libc/time/lib_asctimer.c
Expand Up @@ -28,6 +28,14 @@

#include <nuttx/time.h>

/****************************************************************************
* Pre-processor definitions
****************************************************************************/

#ifndef ARRAY_SIZE
# define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
#endif

/****************************************************************************
* Private Data
****************************************************************************/
Expand Down Expand Up @@ -73,6 +81,13 @@ FAR char *asctime_r(FAR const struct tm *tp, FAR char *buf)
{
char tmp[128];

if (tp == NULL ||
tp->tm_wday >= ARRAY_SIZE(g_wday_name) ||
tp->tm_mon >= ARRAY_SIZE(g_mon_name))
{
return NULL;
}

snprintf(tmp, sizeof(tmp), "%.3s %.3s%3d %.2d:%.2d:%.2d %d\n",
g_wday_name[tp->tm_wday], g_mon_name[tp->tm_mon],
tp->tm_mday, tp->tm_hour, tp->tm_min, tp->tm_sec,
Expand Down