Skip to content

Commit

Permalink
kafka/s/h: Wrap call to lexical_cast in try block
Browse files Browse the repository at this point in the history
- incremental_alter_configs requests were killing connections when
requests supplied an invalid string as a compression_type argument.

- The method lexical_cast invokes to convert a compression to a string
contains a string_switch method without a default clause, this throws
when no matches are found. The solution is to wrap the call to
lexical_cast in a try/catch clause.

- Fixes: redpanda-data#16281
  • Loading branch information
graphcareful committed Jan 31, 2024
1 parent 07ea1bc commit 63efdf2
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/v/kafka/server/handlers/configs/config_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -406,13 +406,17 @@ void parse_and_set_optional(
}
// set property value if preset, otherwise do nothing
if (op == config_resource_operation::set && value) {
auto v = boost::lexical_cast<T>(*value);
auto v_error = validator(*value, v);
if (v_error) {
throw validation_error(*v_error);
}
property.value = std::move(v);
property.op = cluster::incremental_update_operation::set;
try {
auto v = boost::lexical_cast<T>(*value);
auto v_error = validator(*value, v);
if (v_error) {
throw validation_error(*v_error);
}
property.value = std::move(v);
} catch (std::runtime_error const&) {
throw boost::bad_lexical_cast();
}
return;
}
}
Expand Down

0 comments on commit 63efdf2

Please sign in to comment.