From 579bf619f4fa464a58931989a949ddde0e334d19 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Mon, 9 Oct 2017 12:51:49 -0400 Subject: [PATCH] fix segfaults --- .../backends/nntpchan-daemon/libnntpchan/line.cpp | 3 ++- .../nntpchan-daemon/libnntpchan/nntp_handler.cpp | 9 +++++++-- .../backends/nntpchan-daemon/libnntpchan/server.cpp | 13 +++++++------ .../backends/nntpchan-daemon/libnntpchan/server.hpp | 1 - 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/contrib/backends/nntpchan-daemon/libnntpchan/line.cpp b/contrib/backends/nntpchan-daemon/libnntpchan/line.cpp index c7f16a9..74a0cd9 100644 --- a/contrib/backends/nntpchan-daemon/libnntpchan/line.cpp +++ b/contrib/backends/nntpchan-daemon/libnntpchan/line.cpp @@ -28,7 +28,8 @@ namespace nntpchan { void LineReader::OnLine(const char *d, const size_t l) { - std::string line(d, l); + std::string line; + line += std::string(d, l); HandleLine(line); } diff --git a/contrib/backends/nntpchan-daemon/libnntpchan/nntp_handler.cpp b/contrib/backends/nntpchan-daemon/libnntpchan/nntp_handler.cpp index fdf2f3e..ef8c310 100644 --- a/contrib/backends/nntpchan-daemon/libnntpchan/nntp_handler.cpp +++ b/contrib/backends/nntpchan-daemon/libnntpchan/nntp_handler.cpp @@ -31,7 +31,7 @@ namespace nntpchan std::istringstream s; s.str(line); for (std::string part; std::getline(s, part, ' '); ) { - if(part.size()) command.push_back(std::string(part)); + if(part.size()) command.push_back(part); } if(command.size()) HandleCommand(command); @@ -59,14 +59,20 @@ namespace nntpchan { std::size_t diff = end - data ; if(m_article) + { m_article->write(data, diff+2); + m_article->flush(); + } ArticleObtained(); diff += 5; Data(end+5, l-diff); return; } if(m_article) + { m_article->write(data, l); + m_article->flush(); + } } else Data(data, l); @@ -141,7 +147,6 @@ namespace nntpchan { if(m_article) { - m_article->flush(); m_article->close(); m_article = nullptr; QueueLine("239 "+m_articleName); diff --git a/contrib/backends/nntpchan-daemon/libnntpchan/server.cpp b/contrib/backends/nntpchan-daemon/libnntpchan/server.cpp index f1db683..d08e9b1 100644 --- a/contrib/backends/nntpchan-daemon/libnntpchan/server.cpp +++ b/contrib/backends/nntpchan-daemon/libnntpchan/server.cpp @@ -86,15 +86,15 @@ namespace nntpchan uv_read_start((uv_stream_t*) &m_conn, [] (uv_handle_t * h, size_t s, uv_buf_t * b) { IServerConn * self = (IServerConn*) h->data; if(self == nullptr) return; - b->base = self->m_readbuff; - if (s > sizeof(self->m_readbuff)) - b->len = sizeof(self->m_readbuff); - else - b->len = s; + b->base = new char[s]; }, [] (uv_stream_t * s, ssize_t nread, const uv_buf_t * b) { IServerConn * self = (IServerConn*) s->data; - if(self == nullptr) return; + if(self == nullptr) { + delete [] b->base; + return; + } if(nread > 0) { + b->base[nread] = 0; self->m_handler->OnData(b->base, nread); self->SendNextReply(); if(self->m_handler->ShouldClose()) @@ -108,6 +108,7 @@ namespace nntpchan // got eof or error self->Close(); } + delete [] b->base; }); } diff --git a/contrib/backends/nntpchan-daemon/libnntpchan/server.hpp b/contrib/backends/nntpchan-daemon/libnntpchan/server.hpp index aa0945b..87f469f 100644 --- a/contrib/backends/nntpchan-daemon/libnntpchan/server.hpp +++ b/contrib/backends/nntpchan-daemon/libnntpchan/server.hpp @@ -56,7 +56,6 @@ namespace nntpchan uv_loop_t * m_loop; Server * m_parent; IConnHandler * m_handler; - char m_readbuff[65536]; }; class Server