Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

report unparseable data in stoul invalid_argument exception #6396

Merged
merged 2 commits into from Mar 27, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 11 additions & 2 deletions pdns/misc.cc
Expand Up @@ -1360,9 +1360,18 @@ gid_t strToGID(const string &str)
unsigned int pdns_stou(const std::string& str, size_t * idx, int base)
{
if (str.empty()) return 0; // compatibility
unsigned long result = std::stoul(str, idx, base);
unsigned long result;
try {
result = std::stoul(str, idx, base);
}
catch(std::invalid_argument& e) {
throw std::invalid_argument(string(e.what()) + "; (invalid argument during std::stoul); data was \""+str+"\"");
}
catch(std::out_of_range& e) {
throw std::out_of_range(string(e.what()) + "; (out of range during std::stoul); data was \""+str+"\"");
}
if (result > std::numeric_limits<unsigned int>::max()) {
throw std::out_of_range("stou");
throw std::out_of_range("stoul returned result out of unsigned int range; data was \""+str+"\"");
}
return static_cast<unsigned int>(result);
}
Expand Down