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.
This commit is contained in:
zhiweih 2020-07-27 23:09:26 +08:00 committed by GitHub
parent fa599be08c
commit 814b646d17
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 2 deletions

View File

@ -179,7 +179,7 @@ void list_date(void)
time_t now;
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.)
@ -194,7 +194,7 @@ static void date(uint8_t argc, char **argv)
time_t now;
/* output current time */
now = time(RT_NULL);
rt_kprintf("%s", ctime(&now));
rt_kprintf("%.*s", 25, ctime(&now));
}
else if (argc >= 7)
{