Skip to content

Commit

Permalink
Check integer conversion errors when reading TP from file
Browse files Browse the repository at this point in the history
  • Loading branch information
tatsuhiro-t committed Mar 7, 2021
1 parent 9ebb55e commit 2381f7f
Showing 1 changed file with 62 additions and 21 deletions.
83 changes: 62 additions & 21 deletions examples/client_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -93,27 +93,68 @@ int ClientBase::read_transport_params(const char *path,

for (std::string line; std::getline(f, line);) {
if (util::istarts_with_l(line, "initial_max_streams_bidi=")) {
params->initial_max_streams_bidi = strtoul(
line.c_str() + str_size("initial_max_streams_bidi="), nullptr, 10);
} else if (util::istarts_with_l(line, "initial_max_streams_uni=")) {
params->initial_max_streams_uni = strtoul(
line.c_str() + str_size("initial_max_streams_uni="), nullptr, 10);
} else if (util::istarts_with_l(line,
"initial_max_stream_data_bidi_local=")) {
params->initial_max_stream_data_bidi_local = strtoul(
line.c_str() + str_size("initial_max_stream_data_bidi_local="),
nullptr, 10);
} else if (util::istarts_with_l(line,
"initial_max_stream_data_bidi_remote=")) {
params->initial_max_stream_data_bidi_remote = strtoul(
line.c_str() + str_size("initial_max_stream_data_bidi_remote="),
nullptr, 10);
} else if (util::istarts_with_l(line, "initial_max_stream_data_uni=")) {
params->initial_max_stream_data_uni = strtoul(
line.c_str() + str_size("initial_max_stream_data_uni="), nullptr, 10);
} else if (util::istarts_with_l(line, "initial_max_data=")) {
params->initial_max_data =
strtoul(line.c_str() + str_size("initial_max_data="), nullptr, 10);
if (auto n = util::parse_uint(line.c_str() +
str_size("initial_max_streams_bidi="));
!n) {
return -1;
} else {
params->initial_max_streams_bidi = *n;
}
continue;
}

if (util::istarts_with_l(line, "initial_max_streams_uni=")) {
if (auto n = util::parse_uint(line.c_str() +
str_size("initial_max_streams_uni="));
!n) {
return -1;
} else {
params->initial_max_streams_uni = *n;
}
continue;
}

if (util::istarts_with_l(line, "initial_max_stream_data_bidi_local=")) {
if (auto n = util::parse_uint(
line.c_str() + str_size("initial_max_stream_data_bidi_local="));
!n) {
return -1;
} else {
params->initial_max_stream_data_bidi_local = *n;
}
continue;
}

if (util::istarts_with_l(line, "initial_max_stream_data_bidi_remote=")) {
if (auto n = util::parse_uint(
line.c_str() + str_size("initial_max_stream_data_bidi_remote="));
!n) {
return -1;
} else {
params->initial_max_stream_data_bidi_remote = *n;
}
continue;
}

if (util::istarts_with_l(line, "initial_max_stream_data_uni=")) {
if (auto n = util::parse_uint(line.c_str() +
str_size("initial_max_stream_data_uni="));
!n) {
return -1;
} else {
params->initial_max_stream_data_uni = *n;
}
continue;
}

if (util::istarts_with_l(line, "initial_max_data=")) {
if (auto n =
util::parse_uint(line.c_str() + str_size("initial_max_data="));
!n) {
return -1;
} else {
params->initial_max_data = *n;
}
}
}

Expand Down

0 comments on commit 2381f7f

Please sign in to comment.