summaryrefslogtreecommitdiffstats
path: root/lib/libnvpair
diff options
context:
space:
mode:
authorRyan Moeller <[email protected]>2021-06-04 15:53:44 -0400
committerGitHub <[email protected]>2021-06-04 13:53:44 -0600
commit1f8e5b6cb8d28128883a102612d424eebe596d70 (patch)
tree9fc38e5a1ed3a83f9ed18bda7f2008e87023530a /lib/libnvpair
parentf84fe3fc8793e6974402ec32925224e2b404ad8f (diff)
Fix error check in nvlist_print_json_string
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 <[email protected]> Reviewed-by: John Kennedy <[email protected]> Signed-off-by: Ryan Moeller <[email protected]> Closes #12175 Closes #12176
Diffstat (limited to 'lib/libnvpair')
-rw-r--r--lib/libnvpair/libnvpair_json.c15
1 files changed, 7 insertions, 8 deletions
diff --git a/lib/libnvpair/libnvpair_json.c b/lib/libnvpair/libnvpair_json.c
index 37a392391..15b6f4afa 100644
--- a/lib/libnvpair/libnvpair_json.c
+++ b/lib/libnvpair/libnvpair_json.c
@@ -54,6 +54,13 @@ nvlist_print_json_string(FILE *fp, const char *input)
FPRINTF(fp, "\"");
while ((sz = mbrtowc(&c, input, MB_CUR_MAX, &mbr)) > 0) {
+ if (sz == (size_t)-1 || sz == (size_t)-2) {
+ /*
+ * We last read an invalid multibyte character sequence,
+ * so return an error.
+ */
+ return (-1);
+ }
switch (c) {
case '"':
FPRINTF(fp, "\\\"");
@@ -97,14 +104,6 @@ nvlist_print_json_string(FILE *fp, const char *input)
input += sz;
}
- if (sz == (size_t)-1 || sz == (size_t)-2) {
- /*
- * We last read an invalid multibyte character sequence,
- * so return an error.
- */
- return (-1);
- }
-
FPRINTF(fp, "\"");
return (0);
}