Skip to content

Commit

Permalink
lib/csv: Fix some memleak corner-cases (reported by OSS-Fuzz)
Browse files Browse the repository at this point in the history
Fixes OSS-Fuzz#39925
  • Loading branch information
liviuchircu committed Sep 19, 2022
1 parent 2c6c636 commit ff34d21
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/csv.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ csv_record *__parse_csv_record(const str *_in, enum csv_flags parse_flags,
return record;

rfc_4180_parsing:
parse_flags |= CSV_DUP_FIELDS;

if (in.len >= 2 && in.s[in.len - 2] == '\r' && in.s[in.len - 1] == '\n')
in.len -= 2;

Expand Down Expand Up @@ -179,9 +181,12 @@ csv_record *__parse_csv_record(const str *_in, enum csv_flags parse_flags,
*c = '\0';
field.len = c - field.s;

if (!push_csv_field(&field, last, parse_flags & (~CSV_DUP_FIELDS)))
if (!push_csv_field(&field, last, parse_flags)) {
free_f(field.s);
goto oom;
}

free_f(field.s);
last = &(*last)->next;

if (ch == lim - 1)
Expand Down

0 comments on commit ff34d21

Please sign in to comment.