Skip to content

Commit 1411ce6

Browse files
authored
strftime/1: fix validation of non-string argument with number input
There was a incorrect else, that caused jq to not ensure that the argument to strftime/1 is a string when the input is a number; this ends up calling jv_string_value on a non-string value, which does not work, and causes an assert failure. Also fix same bug in strflocaltime/1. Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=67403
1 parent 6f67bae commit 1411ce6

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

src/builtin.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1599,9 +1599,9 @@ static jv f_strftime(jq_state *jq, jv a, jv b) {
15991599
}
16001600
} else if (jv_get_kind(a) != JV_KIND_ARRAY) {
16011601
return ret_error2(a, b, jv_string("strftime/1 requires parsed datetime inputs"));
1602-
} else if (jv_get_kind(b) != JV_KIND_STRING) {
1603-
return ret_error2(a, b, jv_string("strftime/1 requires a string format"));
16041602
}
1603+
if (jv_get_kind(b) != JV_KIND_STRING)
1604+
return ret_error2(a, b, jv_string("strftime/1 requires a string format"));
16051605
struct tm tm;
16061606
if (!jv2tm(a, &tm))
16071607
return ret_error(b, jv_string("strftime/1 requires parsed datetime inputs"));
@@ -1630,9 +1630,9 @@ static jv f_strflocaltime(jq_state *jq, jv a, jv b) {
16301630
a = f_localtime(jq, a);
16311631
} else if (jv_get_kind(a) != JV_KIND_ARRAY) {
16321632
return ret_error2(a, b, jv_string("strflocaltime/1 requires parsed datetime inputs"));
1633-
} else if (jv_get_kind(b) != JV_KIND_STRING) {
1634-
return ret_error2(a, b, jv_string("strflocaltime/1 requires a string format"));
16351633
}
1634+
if (jv_get_kind(b) != JV_KIND_STRING)
1635+
return ret_error2(a, b, jv_string("strflocaltime/1 requires a string format"));
16361636
struct tm tm;
16371637
if (!jv2tm(a, &tm))
16381638
return ret_error(b, jv_string("strflocaltime/1 requires parsed datetime inputs"));

tests/jq.test

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1585,6 +1585,15 @@ try mktime catch .
15851585
["a",1,2,3,4,5,6,7]
15861586
"mktime requires parsed datetime inputs"
15871587

1588+
# oss-fuzz #67403: non-string argument with number input fails assert
1589+
try ["OK", strftime([])] catch ["KO", .]
1590+
0
1591+
["KO","strftime/1 requires a string format"]
1592+
1593+
try ["OK", strflocaltime({})] catch ["KO", .]
1594+
0
1595+
["KO","strflocaltime/1 requires a string format"]
1596+
15881597
# module system
15891598
import "a" as foo; import "b" as bar; def fooa: foo::a; [fooa, bar::a, bar::b, foo::a]
15901599
null

0 commit comments

Comments
 (0)