Skip to content

Commit

Permalink
ostream: fix potential overwrite in StrBuf::sync_impl
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-pentagrid committed Nov 21, 2024
1 parent 5cb453d commit 697a822
Showing 1 changed file with 6 additions and 4 deletions.
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

0 comments on commit 697a822

Please sign in to comment.