Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

ostream: fix potential overwrite in StrBuf::sync_impl #1816

Merged
merged 1 commit into from
Nov 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/plugins/output_format/ostream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,15 @@ class StrBuf : public std::stringbuf
// this is required because of printf() logging
fflush(stdout);

for (auto size = pptr() - pbase(); size > 0; )
auto size_remains = pptr() - pbase();
char* current_position = pbase();
while (size_remains > 0)
{
auto written = write(STDOUT_FILENO, pbase(), size);
ssize_t written = write(STDOUT_FILENO, current_position, size_remains);
if (written < 0)
return -1;
size -= written;
seekoff(written, std::ios_base::cur, std::ios_base::out);
size_remains -= written;
current_position += written;
}
seekpos(0);
return 0;
Expand Down
Loading