fix: guard WinHttp URL port parsing exceptions#60
Conversation
|
Also, the PR description says invalid ports leave the port at default |
std::stol accepts strings like "12312abc" by parsing only the numeric prefix. Use the pos parameter to verify the entire port substring was consumed, and treat trailing garbage as invalid.
|
Good catches, thanks for the review.
|
Problem
WinHttp::ParseUrlcallsstd::stoion the port substring extracted from URLs likehost:port. If the port field is empty, non-numeric, or out of range,std::stoithrowsstd::invalid_argumentorstd::out_of_range, crashing the caller.Changes
std::stoicall in a try-catch block.[1, 65535]are accepted.std::stol'sposparameter to reject partially-numeric port strings (e.g.,host:12312abc).ParsedUrl, which callers already handle as a "skip this URL" signal.Testing
host:,host:abc,host:999999,host:12312abc, and valid URLs to confirm no regression.