Skip to content

Commit

Permalink
strftime/1: fix validation of non-string argument with number input
Browse files Browse the repository at this point in the history
There was a incorrect else, that caused jq to not ensure that the
argument to strftime/1 is a string; this ends up calling jv_string_value
on a non-string value, which does not work, and causes an assert
failure.

In this commit, I also remove some unnecessary else.

Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=67403
  • Loading branch information
emanuele6 committed Mar 15, 2024
1 parent c95b34f commit a3a2aeb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/builtin.c
Original file line number Diff line number Diff line change
Expand Up @@ -1597,11 +1597,11 @@ static jv f_strftime(jq_state *jq, jv a, jv b) {
jv_free(b);
return a;
}
} else if (jv_get_kind(a) != JV_KIND_ARRAY) {
}
if (jv_get_kind(a) != JV_KIND_ARRAY)
return ret_error2(a, b, jv_string("strftime/1 requires parsed datetime inputs"));
} else if (jv_get_kind(b) != JV_KIND_STRING) {
if (jv_get_kind(b) != JV_KIND_STRING)
return ret_error2(a, b, jv_string("strftime/1 requires a string format"));
}
struct tm tm;
if (!jv2tm(a, &tm))
return ret_error(b, jv_string("strftime/1 requires parsed datetime inputs"));
Expand Down
5 changes: 5 additions & 0 deletions tests/jq.test
Original file line number Diff line number Diff line change
Expand Up @@ -1580,6 +1580,11 @@ try mktime catch .
["a",1,2,3,4,5,6,7]
"mktime requires parsed datetime inputs"

# oss-fuzz #67403: non-string argument with number input fails assert
try ["OK", strftime([])] catch ["KO", .]
0
["KO","strftime/1 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
Expand Down

0 comments on commit a3a2aeb

Please sign in to comment.