diff options
| author | zhiweih <[email protected]> | 2020-07-27 23:09:26 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2020-07-27 23:09:26 +0800 |
| commit | 814b646d17fb3219b2b832be9d5df676a881614e (patch) | |
| tree | 801341299d6ff3acfe575b8f37efb6ff43eea924 /components/drivers | |
| parent | fa599be08cb79b16d9bdb1456e195ac134b0f34f (diff) | |
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.
Diffstat (limited to 'components/drivers')
| -rw-r--r-- | components/drivers/rtc/rtc.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/components/drivers/rtc/rtc.c b/components/drivers/rtc/rtc.c index e17c0fe7dd..682515ce98 100644 --- a/components/drivers/rtc/rtc.c +++ b/components/drivers/rtc/rtc.c @@ -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) { |
