Skip to content
Myr

Fix leaks on invalid input for strftime, strflocaltime and mktime

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Mattias Wadman · committed by Emanuele Torre · parent 97c6d28 · Browse files · 2 files+15 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+15 added−1 removed

  • tests:+13 added−0 removed
  • other:+2 added−1 removed

2 files+15 added−1 removed

modified:src/builtin.c+2 added-1 removed
1459 unmodified lines
1460#define TO_TM_FIELD(t, j, i) \1461 do { \1462 jv n = jv_array_get(jv_copy(j), (i)); \1463 if (jv_get_kind(n) != (JV_KIND_NUMBER)) { \1464 jv_free(n); \1465 jv_free(j); \1466 return 0; \1467 } \1468 t = jv_number_value(n); \
161 unmodified lines
1630 return ret_error2(a, b, jv_string("strflocaltime/1 requires a string format"));1631 }1632 struct tm tm;1633 if (!jv2tm(a, &tm))1633 return jv_invalid_with_msg(jv_string("strflocaltime/1 requires parsed datetime inputs"));1634 return ret_error(b, jv_string("strflocaltime/1 requires parsed datetime inputs"));1635 const char *fmt = jv_string_value(b);1636 size_t alloced = strlen(fmt) + 100;1637 char *buf = alloca(alloced);1638 size_t n = strftime(buf, alloced, fmt, &tm);
241 unmodified lines
modified:tests/jq.test+13 added
1509 unmodified lines
1510gmtime151114255995071512[2015,2,5,23,51,47,4,63]15131514# test invalid tm input1515try strftime("%Y-%m-%dT%H:%M:%SZ") catch .1516["a",1,2,3,4,5,6,7]1517"strftime/1 requires parsed datetime inputs"15181519try strflocaltime("%Y-%m-%dT%H:%M:%SZ") catch .1520["a",1,2,3,4,5,6,7]1521"strflocaltime/1 requires parsed datetime inputs"15221523try mktime catch .1524["a",1,2,3,4,5,6,7]1525"mktime requires parsed datetime inputs"15261527# module system1528import "a" as foo; import "b" as bar; def fooa: foo::a; [fooa, bar::a, bar::b, foo::a]1529null1530["a","b","c","a"]
382 unmodified lines