From d8dcce7f2aae581dcce707856430c2f94cbf41e5 Mon Sep 17 00:00:00 2001 From: red0124 <75804778+red0124@users.noreply.github.com> Date: Thu, 29 Feb 2024 22:03:20 +0100 Subject: [PATCH] Fix buffer overflow on multiline csv data containing null characters (#38) --- include/ss/parser.hpp | 5 +++-- ssp.hpp | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/include/ss/parser.hpp b/include/ss/parser.hpp index 154a881..b41c195 100644 --- a/include/ss/parser.hpp +++ b/include/ss/parser.hpp @@ -912,16 +912,17 @@ private: 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; } diff --git a/ssp.hpp b/ssp.hpp index 4cc906e..6ec0a11 100644 --- a/ssp.hpp +++ b/ssp.hpp @@ -3088,16 +3088,17 @@ private: 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; }