Skip to content

Commit c810696

Browse files
committed
unescape: fix overflow on unescaping string (oss-fuzz 22132)
Signed-off-by: Eduardo Silva <[email protected]>
1 parent 29442b9 commit c810696

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/flb_unescape.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,17 +126,18 @@ int flb_unescape_string_utf8(const char *in_buf, int sz, char *out_buf)
126126
{
127127
uint32_t ch;
128128
char temp[4];
129+
const char *end;
129130
const char *next;
130131

131132
int count_out = 0;
132133
int count_in = 0;
133134
int esc_in = 0;
134135
int esc_out = 0;
135136

136-
while (*in_buf && count_in < sz) {
137+
end = in_buf + sz;
138+
while (in_buf < end && *in_buf && count_in < sz) {
137139
next = in_buf + 1;
138-
139-
if (*in_buf == '\\') {
140+
if (next < end && *in_buf == '\\') {
140141
esc_in = 2;
141142
switch (*next) {
142143
case '"':

0 commit comments

Comments
 (0)