From 2adfbcaeca0c3b565583cbb3d808c1e02ac8bd6d Mon Sep 17 00:00:00 2001 From: liukangcc Date: Wed, 15 Sep 2021 14:16:38 +0800 Subject: [PATCH 1/3] [update] enable asctime_r function parameter legal. --- components/libc/compilers/common/time.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/components/libc/compilers/common/time.c b/components/libc/compilers/common/time.c index 50f6d4c71e..efcfe4dec0 100644 --- a/components/libc/compilers/common/time.c +++ b/components/libc/compilers/common/time.c @@ -239,6 +239,9 @@ RTM_EXPORT(mktime); char* asctime_r(const struct tm *t, char *buf) { + RT_ASSERT(rt_strlen(days) > (t->tm_wday << 2)); + RT_ASSERT(rt_strlen(months) > (t->tm_mon << 2)); + /* "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)); From 169b09004ee9ed15c1e8cb15c7d2fe3042895f29 Mon Sep 17 00:00:00 2001 From: liukangcc Date: Mon, 27 Sep 2021 14:18:54 +0800 Subject: [PATCH 2/3] [update] asctime_r return value. --- components/libc/compilers/common/time.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/components/libc/compilers/common/time.c b/components/libc/compilers/common/time.c index efcfe4dec0..840629f973 100644 --- a/components/libc/compilers/common/time.c +++ b/components/libc/compilers/common/time.c @@ -239,8 +239,28 @@ RTM_EXPORT(mktime); char* asctime_r(const struct tm *t, char *buf) { - RT_ASSERT(rt_strlen(days) > (t->tm_wday << 2)); - RT_ASSERT(rt_strlen(months) > (t->tm_mon << 2)); + /* Checking input validity */ + if (rt_strlen(days) <= (t->tm_wday << 2) || rt_strlen(months) <= (t->tm_mon << 2)) + { + LOG_W("The input 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)); From a74b0ae3884ef4275e3b7949072492e3cacdf486 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Mon, 27 Sep 2021 07:40:24 -0400 Subject: [PATCH 3/3] =?UTF-8?q?[libc][time]=E4=BC=98=E5=8C=96=E8=AD=A6?= =?UTF-8?q?=E5=91=8A=E8=BE=93=E5=87=BA=E5=86=85=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/libc/compilers/common/time.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/libc/compilers/common/time.c b/components/libc/compilers/common/time.c index 840629f973..c54ec2aac5 100644 --- a/components/libc/compilers/common/time.c +++ b/components/libc/compilers/common/time.c @@ -29,7 +29,7 @@ #include #endif -#define DBG_TAG "TIME" +#define DBG_TAG "time" #define DBG_LVL DBG_INFO #include @@ -242,7 +242,7 @@ 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("The input exceeded the limit, please check it."); + 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);