nghttpx: Fix bug that reading QUIC secret file fails without line separator

This commit is contained in:
Tatsuhiro Tsujikawa 2021-09-24 17:50:28 +09:00
parent 27e6d56d83
commit d0e8efac4d
1 changed files with 4 additions and 3 deletions

View File

@ -248,11 +248,12 @@ read_quic_secret_file(const StringRef &path) {
std::array<char, 4096> buf; std::array<char, 4096> buf;
while (f.getline(buf.data(), buf.size())) { while (f.getline(buf.data(), buf.size())) {
if (f.gcount() == 1 || buf[0] == '#') { auto len = strlen(buf.data());
if (len == 0 || buf[0] == '#') {
continue; 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)) { if (s.size() != expectedlen * 2 || !util::is_hex_string(s)) {
LOG(ERROR) << "frontend-quic-secret-file: each line must be a " LOG(ERROR) << "frontend-quic-secret-file: each line must be a "
<< expectedlen * 2 << " bytes hex encoded string"; << 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) LOG(ERROR)
<< "frontend-quic-secret-file: error occurred while reading file " << "frontend-quic-secret-file: error occurred while reading file "
<< path; << path;