mirror of
https://github.com/janet-lang/janet
synced 2026-11-23 15:47:11 +00:00
fix stack over-read in os/strftime when the result does not fit (#1938)
This commit is contained in:
1 parent
c4a803c8fb
commit
f63f7ccdf3
2 files changed
+8
-2
No files matched your search
+2
-2
@@ -1996,8 +1996,8 @@ JANET_CORE_FN(os_strftime,
|
||||
struct tm t_infos;
|
||||
struct tm *t_info = time_to_tm(argv, argc, 1, &t_infos);
|
||||
char buf[SIZETIMEFMT];
|
||||
(void)strftime(buf, sizeof(buf), fmt, t_info);
|
||||
return janet_cstringv(buf);
|
||||
size_t len = strftime(buf, sizeof(buf), fmt, t_info);
|
||||
return janet_stringv((const uint8_t *)buf, (int32_t) len);
|
||||
}
|
||||
|
||||
static int entry_getdst(Janet env_entry) {
|
||||
|
||||
@@ -67,6 +67,12 @@
|
||||
(assert (= (try (os/strftime "%H:%M:%") ([err] err))
|
||||
"invalid conversion specifier")
|
||||
"invalid conversion specifier 2")
|
||||
# strftime leaves its buffer indeterminate when the result does not fit,
|
||||
# so an oversized result must not be read back with strlen.
|
||||
(assert (= (os/strftime (string/repeat "a" 249) 0) (string/repeat "a" 249))
|
||||
"strftime result that fills the buffer")
|
||||
(assert (= (os/strftime (string/repeat "%Y" 200) 0) "")
|
||||
"strftime result too long for the buffer")
|
||||
|
||||
# 07db4c530
|
||||
(os/setenv "TESTENV1" "v1")
|
||||
|
||||
Reference in new issue
Block a user