Commit 6f967c6e authored by Tatsuhiro Tsujikawa's avatar Tatsuhiro Tsujikawa

Fix errors reported by coverity scan

parent b8a43db8
...@@ -624,33 +624,30 @@ int Http2Handler::read_clear() { ...@@ -624,33 +624,30 @@ int Http2Handler::read_clear() {
int rv; int rv;
std::array<uint8_t, 8_k> buf; std::array<uint8_t, 8_k> buf;
for (;;) { ssize_t nread;
ssize_t nread; while ((nread = read(fd_, buf.data(), buf.size())) == -1 && errno == EINTR)
while ((nread = read(fd_, buf.data(), buf.size())) == -1 && errno == EINTR) ;
; if (nread == -1) {
if (nread == -1) { if (errno == EAGAIN || errno == EWOULDBLOCK) {
if (errno == EAGAIN || errno == EWOULDBLOCK) { return write_(*this);
break;
}
return -1;
}
if (nread == 0) {
return -1;
} }
return -1;
}
if (nread == 0) {
return -1;
}
if (get_config()->hexdump) { if (get_config()->hexdump) {
util::hexdump(stdout, buf.data(), nread); util::hexdump(stdout, buf.data(), nread);
} }
rv = nghttp2_session_mem_recv(session_, buf.data(), nread); rv = nghttp2_session_mem_recv(session_, buf.data(), nread);
if (rv < 0) { if (rv < 0) {
if (rv != NGHTTP2_ERR_BAD_CLIENT_MAGIC) { if (rv != NGHTTP2_ERR_BAD_CLIENT_MAGIC) {
std::cerr << "nghttp2_session_mem_recv() returned error: " std::cerr << "nghttp2_session_mem_recv() returned error: "
<< nghttp2_strerror(rv) << std::endl; << nghttp2_strerror(rv) << std::endl;
}
return -1;
} }
break; return -1;
} }
return write_(*this); return write_(*this);
...@@ -746,40 +743,36 @@ int Http2Handler::read_tls() { ...@@ -746,40 +743,36 @@ int Http2Handler::read_tls() {
ERR_clear_error(); ERR_clear_error();
for (;;) { auto rv = SSL_read(ssl_, buf.data(), buf.size());
auto rv = SSL_read(ssl_, buf.data(), buf.size());
if (rv <= 0) {
if (rv <= 0) { auto err = SSL_get_error(ssl_, rv);
auto err = SSL_get_error(ssl_, rv); switch (err) {
switch (err) { case SSL_ERROR_WANT_READ:
case SSL_ERROR_WANT_READ: return write_(*this);
goto fin; case SSL_ERROR_WANT_WRITE:
case SSL_ERROR_WANT_WRITE: // renegotiation started
// renegotiation started return -1;
return -1; default:
default: return -1;
return -1;
}
} }
}
auto nread = rv; auto nread = rv;
if (get_config()->hexdump) { if (get_config()->hexdump) {
util::hexdump(stdout, buf.data(), nread); util::hexdump(stdout, buf.data(), nread);
} }
rv = nghttp2_session_mem_recv(session_, buf.data(), nread); rv = nghttp2_session_mem_recv(session_, buf.data(), nread);
if (rv < 0) { if (rv < 0) {
if (rv != NGHTTP2_ERR_BAD_CLIENT_MAGIC) { if (rv != NGHTTP2_ERR_BAD_CLIENT_MAGIC) {
std::cerr << "nghttp2_session_mem_recv() returned error: " std::cerr << "nghttp2_session_mem_recv() returned error: "
<< nghttp2_strerror(rv) << std::endl; << nghttp2_strerror(rv) << std::endl;
}
return -1;
} }
break; return -1;
} }
fin:
return write_(*this); return write_(*this);
} }
......
...@@ -505,7 +505,8 @@ struct DownstreamAddrGroupConfig { ...@@ -505,7 +505,8 @@ struct DownstreamAddrGroupConfig {
DownstreamAddrGroupConfig(const StringRef &pattern) DownstreamAddrGroupConfig(const StringRef &pattern)
: pattern(pattern), : pattern(pattern),
affinity{SessionAffinity::NONE}, affinity{SessionAffinity::NONE},
redirect_if_not_tls(false) {} redirect_if_not_tls(false),
timeout{} {}
StringRef pattern; StringRef pattern;
StringRef mruby_file; StringRef mruby_file;
......
...@@ -469,9 +469,9 @@ int Connection::tls_handshake() { ...@@ -469,9 +469,9 @@ int Connection::tls_handshake() {
<< ERR_error_string(ERR_get_error(), nullptr); << ERR_error_string(ERR_get_error(), nullptr);
} }
struct iovec iov; struct iovec iov[1];
auto iovcnt = tls.wbuf.riovec(&iov, 1); auto iovcnt = tls.wbuf.riovec(iov, 1);
auto nwrite = writev_clear(&iov, iovcnt); auto nwrite = writev_clear(iov, iovcnt);
if (nwrite > 0) { if (nwrite > 0) {
tls.wbuf.drain(nwrite); tls.wbuf.drain(nwrite);
} }
......
...@@ -1097,6 +1097,7 @@ int on_response_headers(Http2Session *http2session, Downstream *downstream, ...@@ -1097,6 +1097,7 @@ int on_response_headers(Http2Session *http2session, Downstream *downstream,
auto status = resp.fs.header(http2::HD__STATUS); auto status = resp.fs.header(http2::HD__STATUS);
// libnghttp2 guarantees this exists and can be parsed // libnghttp2 guarantees this exists and can be parsed
assert(status);
auto status_code = http2::parse_http_status_code(status->value); auto status_code = http2::parse_http_status_code(status->value);
resp.http_status = status_code; resp.http_status = status_code;
......
...@@ -190,7 +190,8 @@ struct SharedDownstreamAddr { ...@@ -190,7 +190,8 @@ struct SharedDownstreamAddr {
SharedDownstreamAddr() SharedDownstreamAddr()
: balloc(1024, 1024), : balloc(1024, 1024),
affinity{SessionAffinity::NONE}, affinity{SessionAffinity::NONE},
redirect_if_not_tls{false} {} redirect_if_not_tls{false},
timeout{} {}
SharedDownstreamAddr(const SharedDownstreamAddr &) = delete; SharedDownstreamAddr(const SharedDownstreamAddr &) = delete;
SharedDownstreamAddr(SharedDownstreamAddr &&) = delete; SharedDownstreamAddr(SharedDownstreamAddr &&) = delete;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment