Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions httplib.h
Original file line number Diff line number Diff line change
Expand Up @@ -6385,13 +6385,16 @@ inline bool parse_www_authenticate(const Response &res,
auto beg = std::sregex_iterator(s.begin(), s.end(), re);
for (auto i = beg; i != std::sregex_iterator(); ++i) {
const auto &m = *i;
// Ensure we have at least the expected capture groups
if (m.size() < 4) continue;

auto key = s.substr(static_cast<size_t>(m.position(1)),
static_cast<size_t>(m.length(1)));
auto val = m.length(2) > 0
? s.substr(static_cast<size_t>(m.position(2)),
auto val = (m.size() > 2 && m.length(2) > 0)
? s.substr(static_cast<size_t>(m.position(2)),
static_cast<size_t>(m.length(2)))
: s.substr(static_cast<size_t>(m.position(3)),
static_cast<size_t>(m.length(3)));
: (m.size() > 3 ? s.substr(static_cast<size_t>(m.position(3)),
static_cast<size_t>(m.length(3))) : "");
auth[key] = val;
}
return true;
Expand Down
Loading