-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
builtin.c: fix signed integer overflow in jv2tm #3070
Conversation
72ceb41
to
60e95a6
Compare
This does not solve the problem fully; it still underflows if you use |
src/builtin.c
Outdated
offsetof(struct tm, tm_yday), | ||
}; | ||
|
||
jv_array_foreach(a, i, n) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I replaced the TO_TM_FIELD
macro repeated 8 times with a loop over offsets
bfd895c
to
5f61b1f
Compare
Now, time functions accept array inputs even if they don't have all the elements, 0 will be assumed if a value is not present. Also, jv2tm now properly clamps large number values to a signed 32-bit integer and rejects nan. Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=65885
Why did you leave $ ./jq -n '[2024,7,20] | todate, mktime'
"2024-08-20T00:00:00Z"
jq: error (at <unknown>): mktime requires parsed datetime inputs |
I didn't touch if (jv_array_length(jv_copy(a)) < 6)
return ret_error(a, jv_string("mktime requires parsed datetime inputs")); That can be removed now |
This check was redundant and useless since jv2tm() used to require 8 elements, and errored anyway if not enough elements were provided. After commit bc96146, this check also prevents mktime/0 from accepting now supported0 inputs with less than 8 elements. Ref: jqlang#3070 (comment) Reported-by: itchyny <itchyny@cybozu.co.jp>
This check was redundant and useless since jv2tm() used to require 8 elements, and errored anyway if not enough elements were provided. After commit bc96146, this check also prevents mktime/0 from accepting now supported inputs with less than 8 elements. Ref: jqlang#3070 (comment) Reported-by: itchyny <itchyny@cybozu.co.jp>
This check was redundant and useless since jv2tm() used to require 8 elements, and errored anyway if not enough elements were provided. After commit bc96146, this check also prevents mktime/0 from accepting now supported inputs with less than 8 elements. Ref: #3070 (comment) Reported-by: itchyny <itchyny@cybozu.co.jp>
jv2tm
now properly clamps large number values to a signed 32-bit integer and rejects nan.Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=65885