Skip to content

Commit

Permalink
utils: fix bad handling of utf-8 parsing (oss-fuzz 26304)
Browse files Browse the repository at this point in the history
Signed-off-by: davkor <david@adalogics.com>
  • Loading branch information
DavidKorczynski authored and edsiper committed Nov 6, 2020
1 parent 3a84a8a commit 73410b3
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/flb_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,9 @@ int flb_utils_write_str(char *buf, int *off, size_t size,
return FLB_FALSE;
}
len = snprintf(tmp, sizeof(tmp) - 1, "\\u%.4hhx", (unsigned char) c);
if ((available - written) < len) {
return FLB_FALSE;
}
encoded_to_buf(p, tmp, len);
p += len;
}
Expand Down Expand Up @@ -677,6 +680,9 @@ int flb_utils_write_str(char *buf, int *off, size_t size,
}
else {
len = snprintf(tmp, sizeof(tmp) - 1, "\\u%.4x", codepoint);
if ((available - written) < len) {
return FLB_FALSE;
}
encoded_to_buf(p, tmp, len);
p += len;
}
Expand Down Expand Up @@ -708,6 +714,9 @@ int flb_utils_write_str(char *buf, int *off, size_t size,
}
else {
len = snprintf(tmp, sizeof(tmp) - 1, "\\u%04x", codepoint);
if ((available - written) < len) {
return FLB_FALSE;
}
encoded_to_buf(p, tmp, len);
p += len;
}
Expand Down

0 comments on commit 73410b3

Please sign in to comment.