summaryrefslogtreecommitdiff
path: root/components
diff options
context:
space:
mode:
authorguo <[email protected]>2021-09-27 21:37:36 +0800
committerGitHub <[email protected]>2021-09-27 21:37:36 +0800
commit4c1c946ba3956861e5aa818f9df3c0938b311eba (patch)
treef933594cdab14df88ef9dfc3f2b7bfdd6cd901e0 /components
parentb7903b293879e24c694c24710e521378576fdcf4 (diff)
parenta74b0ae3884ef4275e3b7949072492e3cacdf486 (diff)
Merge pull request #5068 from liukangcc/time
[update] enable asctime_r function parameter legal.
Diffstat (limited to 'components')
-rw-r--r--components/libc/compilers/common/time.c25
1 files changed, 24 insertions, 1 deletions
diff --git a/components/libc/compilers/common/time.c b/components/libc/compilers/common/time.c
index 7aa8d9300b..f81844f8e9 100644
--- a/components/libc/compilers/common/time.c
+++ b/components/libc/compilers/common/time.c
@@ -29,7 +29,7 @@
#include <rtdevice.h>
#endif
-#define DBG_TAG "TIME"
+#define DBG_TAG "time"
#define DBG_LVL DBG_INFO
#include <rtdbg.h>
@@ -239,6 +239,29 @@ RTM_EXPORT(mktime);
char* asctime_r(const struct tm *t, char *buf)
{
+ /* Checking input validity */
+ if (rt_strlen(days) <= (t->tm_wday << 2) || rt_strlen(months) <= (t->tm_mon << 2))
+ {
+ LOG_W("asctime_r: the input parameters exceeded the limit, please check it.");
+ *(int*) buf = *(int*) days;
+ *(int*) (buf + 4) = *(int*) months;
+ num2str(buf + 8, t->tm_mday);
+ if (buf[8] == '0')
+ buf[8] = ' ';
+ buf[10] = ' ';
+ num2str(buf + 11, t->tm_hour);
+ buf[13] = ':';
+ num2str(buf + 14, t->tm_min);
+ buf[16] = ':';
+ num2str(buf + 17, t->tm_sec);
+ buf[19] = ' ';
+ num2str(buf + 20, 2000 / 100);
+ num2str(buf + 22, 2000 % 100);
+ buf[24] = '\n';
+ buf[25] = '\0';
+ return buf;
+ }
+
/* "Wed Jun 30 21:49:08 1993\n" */
*(int*) buf = *(int*) (days + (t->tm_wday << 2));
*(int*) (buf + 4) = *(int*) (months + (t->tm_mon << 2));