From d0e8efac4dd0411a8dab8ede6ec5e664f73c77a2 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Fri, 24 Sep 2021 17:50:28 +0900 Subject: [PATCH] nghttpx: Fix bug that reading QUIC secret file fails without line separator --- src/shrpx_config.cc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/shrpx_config.cc b/src/shrpx_config.cc index d498ef02..64c401ed 100644 --- a/src/shrpx_config.cc +++ b/src/shrpx_config.cc @@ -248,11 +248,12 @@ read_quic_secret_file(const StringRef &path) { std::array buf; while (f.getline(buf.data(), buf.size())) { - if (f.gcount() == 1 || buf[0] == '#') { + auto len = strlen(buf.data()); + if (len == 0 || buf[0] == '#') { continue; } - auto s = StringRef{std::begin(buf), std::begin(buf) + f.gcount() - 1}; + auto s = StringRef{std::begin(buf), std::begin(buf) + len}; if (s.size() != expectedlen * 2 || !util::is_hex_string(s)) { LOG(ERROR) << "frontend-quic-secret-file: each line must be a " << expectedlen * 2 << " bytes hex encoded string"; @@ -282,7 +283,7 @@ read_quic_secret_file(const StringRef &path) { } } - if (f.bad()) { + if (f.bad() || (!f.eof() && f.fail())) { LOG(ERROR) << "frontend-quic-secret-file: error occurred while reading file " << path;