未验证 提交 814b646d 编写于 作者: Z zhiweih 提交者: GitHub

Specify date string length in FINSH date command.

libc ctime returns a fixed 25 character string without a NULL terminator. Print it without specifying length in FINSH date command prints extra contents and could potentially be dangerous.
上级 fa599be0
...@@ -179,7 +179,7 @@ void list_date(void) ...@@ -179,7 +179,7 @@ void list_date(void)
time_t now; time_t now;
now = time(RT_NULL); now = time(RT_NULL);
rt_kprintf("%s\n", ctime(&now)); rt_kprintf("%.*s\n", 25, ctime(&now));
} }
FINSH_FUNCTION_EXPORT(list_date, show date and time.) FINSH_FUNCTION_EXPORT(list_date, show date and time.)
...@@ -194,7 +194,7 @@ static void date(uint8_t argc, char **argv) ...@@ -194,7 +194,7 @@ static void date(uint8_t argc, char **argv)
time_t now; time_t now;
/* output current time */ /* output current time */
now = time(RT_NULL); now = time(RT_NULL);
rt_kprintf("%s", ctime(&now)); rt_kprintf("%.*s", 25, ctime(&now));
} }
else if (argc >= 7) else if (argc >= 7)
{ {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册