-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
infinite loop in nvlist_print_json() #12175
Labels
Status: Triage Needed
New issue which needs to be triaged
Type: Defect
Incorrect behavior (e.g. crash, hang)
Comments
cfcs
added
Status: Triage Needed
New issue which needs to be triaged
Type: Defect
Incorrect behavior (e.g. crash, hang)
labels
Jun 1, 2021
ghost
pushed a commit
to truenas/zfs
that referenced
this issue
Jun 1, 2021
Move check for errors from mbrtowc() into the loop. The error values are not actually negative, so we don't break out of the loop when they are encountered. Fixes: openzfs#12175 Signed-off-by: Ryan Moeller <ryan@iXsystems.com>
ghost
mentioned this issue
Jun 1, 2021
13 tasks
ghost
linked a pull request
Jun 1, 2021
that will
close
this issue
13 tasks
tonynguien
pushed a commit
that referenced
this issue
Jun 4, 2021
Move check for errors from mbrtowc() into the loop. The error values are not actually negative, so we don't break out of the loop when they are encountered. Reviewed-by: Tony Nguyen <tony.nguyen@delphix.com> Reviewed-by: John Kennedy <john.kennedy@delphix.com> Signed-off-by: Ryan Moeller <ryan@iXsystems.com> Closes #12175 Closes #12176
behlendorf
pushed a commit
to behlendorf/zfs
that referenced
this issue
Jun 8, 2021
Move check for errors from mbrtowc() into the loop. The error values are not actually negative, so we don't break out of the loop when they are encountered. Reviewed-by: Tony Nguyen <tony.nguyen@delphix.com> Reviewed-by: John Kennedy <john.kennedy@delphix.com> Signed-off-by: Ryan Moeller <ryan@iXsystems.com> Closes openzfs#12175 Closes openzfs#12176
behlendorf
pushed a commit
to behlendorf/zfs
that referenced
this issue
Jun 8, 2021
Move check for errors from mbrtowc() into the loop. The error values are not actually negative, so we don't break out of the loop when they are encountered. Reviewed-by: Tony Nguyen <tony.nguyen@delphix.com> Reviewed-by: John Kennedy <john.kennedy@delphix.com> Signed-off-by: Ryan Moeller <ryan@iXsystems.com> Closes openzfs#12175 Closes openzfs#12176
behlendorf
pushed a commit
to behlendorf/zfs
that referenced
this issue
Jun 9, 2021
Move check for errors from mbrtowc() into the loop. The error values are not actually negative, so we don't break out of the loop when they are encountered. Reviewed-by: Tony Nguyen <tony.nguyen@delphix.com> Reviewed-by: John Kennedy <john.kennedy@delphix.com> Signed-off-by: Ryan Moeller <ryan@iXsystems.com> Closes openzfs#12175 Closes openzfs#12176
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Status: Triage Needed
New issue which needs to be triaged
Type: Defect
Incorrect behavior (e.g. crash, hang)
System information
Describe the problem you're observing
When printing a string that ends in an invalid UTF-8 sequence, nvlist_print_json_string goes into an infinite loop because
mbrtowc
will return a negative result when passed a&mbr
that has detected an error, without looking atinput
or the other parameters.It's quite possible that
mbrtowc
behaves differently in other implementations, I'm usingglibc
.The conditional below is
true
when when the result is negative becausesize_t
is unsigned (maybe it should bessize_t
?), meaning it stays in the loop wheneversz != 0
:I'm not sure how this should be fixed: either changing the type of
sz
or ensuring thatinput
does stay smaller than the end ofinput
seem like decent candidates for a solution.I would have expected that the function should either fail, or print a truncated version of the string.
Describe how to reproduce the problem
hang.hex
:This is the nvlist encoding of
trigger.c
:xxd -ps -r hang.hex > hang.bin gcc -std=c18 -Wall -pie -I/usr/include/libzfs/ trigger.c -lnvpair -luutil -o trigger.exe ./trigger.exe hang.bin
This (on linux with glibc) outputs
Here is
ldd ./trigger.exe
:Background
I ran into this when using
afl-fuzz
to look for cases where my own implementation oflibnvlist
disagrees with the upstream implementation, using the JSON output to compare outputs from decoding.The function is not part of the standard Solaris interface, but I was unable to find much documentation on the expected semantics in the serialization format, so I thought this would be an easy way to find inconsistencies.
I don't rely on
nvlist_print_json()
for anything important, and don't know if anybody else does, but I guess it would be neat if this behaviour could be changed.The text was updated successfully, but these errors were encountered: