Fix leaks on invalid input for strftime, strflocaltime and mktime
This commit is contained in:
1 parent
97c6d2848c
commit
16ae275d4c
2 files changed
+15
-1
No files matched your search
+2
-1
@@ -1461,6 +1461,7 @@ static jv f_strptime(jq_state *jq, jv a, jv b) {
|
||||
do { \
|
||||
jv n = jv_array_get(jv_copy(j), (i)); \
|
||||
if (jv_get_kind(n) != (JV_KIND_NUMBER)) { \
|
||||
jv_free(n); \
|
||||
jv_free(j); \
|
||||
return 0; \
|
||||
} \
|
||||
@@ -1630,7 +1631,7 @@ static jv f_strflocaltime(jq_state *jq, jv a, jv b) {
|
||||
}
|
||||
struct tm tm;
|
||||
if (!jv2tm(a, &tm))
|
||||
return jv_invalid_with_msg(jv_string("strflocaltime/1 requires parsed datetime inputs"));
|
||||
return ret_error(b, jv_string("strflocaltime/1 requires parsed datetime inputs"));
|
||||
const char *fmt = jv_string_value(b);
|
||||
size_t alloced = strlen(fmt) + 100;
|
||||
char *buf = alloca(alloced);
|
||||
|
||||
@@ -1511,6 +1511,19 @@ gmtime
|
||||
1425599507
|
||||
[2015,2,5,23,51,47,4,63]
|
||||
|
||||
# test invalid tm input
|
||||
try strftime("%Y-%m-%dT%H:%M:%SZ") catch .
|
||||
["a",1,2,3,4,5,6,7]
|
||||
"strftime/1 requires parsed datetime inputs"
|
||||
|
||||
try strflocaltime("%Y-%m-%dT%H:%M:%SZ") catch .
|
||||
["a",1,2,3,4,5,6,7]
|
||||
"strflocaltime/1 requires parsed datetime inputs"
|
||||
|
||||
try mktime catch .
|
||||
["a",1,2,3,4,5,6,7]
|
||||
"mktime requires parsed datetime inputs"
|
||||
|
||||
# module system
|
||||
import "a" as foo; import "b" as bar; def fooa: foo::a; [fooa, bar::a, bar::b, foo::a]
|
||||
null
|
||||
|
||||
Reference in new issue
Block a user