Skip to content

Commit

Permalink
Fix buffer overflow on multiline csv data containing null characters
Browse files Browse the repository at this point in the history
  • Loading branch information
red0124 committed Feb 29, 2024
1 parent ddaa446 commit c36340a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
5 changes: 3 additions & 2 deletions include/ss/parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -912,16 +912,17 @@ class parser {

void undo_remove_eol(char* buffer, size_t& string_end) {
if (crlf_) {
std::copy_n("\r\n\0", 3, buffer + string_end);
std::copy_n("\r\n", 2, buffer + string_end);
string_end += 2;
} else {
std::copy_n("\n\0", 2, buffer + string_end);
std::copy_n("\n", 1, buffer + string_end);
string_end += 1;
}
}

size_t remove_eol(char*& buffer, size_t ssize) {
if (buffer[ssize - 1] != '\n') {
crlf_ = false;
return ssize;
}

Expand Down
5 changes: 3 additions & 2 deletions ssp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3088,16 +3088,17 @@ class parser {

void undo_remove_eol(char* buffer, size_t& string_end) {
if (crlf_) {
std::copy_n("\r\n\0", 3, buffer + string_end);
std::copy_n("\r\n", 2, buffer + string_end);
string_end += 2;
} else {
std::copy_n("\n\0", 2, buffer + string_end);
std::copy_n("\n", 1, buffer + string_end);
string_end += 1;
}
}

size_t remove_eol(char*& buffer, size_t ssize) {
if (buffer[ssize - 1] != '\n') {
crlf_ = false;
return ssize;
}

Expand Down

0 comments on commit c36340a

Please sign in to comment.