nghttp: Check maximum value of -c option

This commit is contained in:
Tatsuhiro Tsujikawa 2016-09-17 22:22:59 +09:00
parent a7e0a69f97
commit f19b0724a3
1 changed files with 11 additions and 6 deletions

View File

@ -2820,16 +2820,21 @@ int main(int argc, char **argv) {
case 'm': case 'm':
config.multiply = strtoul(optarg, nullptr, 10); config.multiply = strtoul(optarg, nullptr, 10);
break; break;
case 'c': case 'c': {
errno = 0; auto n = util::parse_uint_with_unit(optarg);
config.header_table_size = util::parse_uint_with_unit(optarg); if (n == -1) {
if (config.header_table_size == -1) {
std::cerr << "-c: Bad option value: " << optarg << std::endl; std::cerr << "-c: Bad option value: " << optarg << std::endl;
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
config.min_header_table_size = if (n > std::numeric_limits<uint32_t>::max()) {
std::min(config.min_header_table_size, config.header_table_size); std::cerr << "-c: Value too large. It should be less than or equal to "
<< std::numeric_limits<uint32_t>::max() << std::endl;
exit(EXIT_FAILURE);
}
config.header_table_size = n;
config.min_header_table_size = std::min(config.min_header_table_size, n);
break; break;
}
case '?': case '?':
util::show_candidates(argv[optind - 1], long_options); util::show_candidates(argv[optind - 1], long_options);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);