From 8ae972b82bee94419c7e958e85eaa625b35e8d7f Mon Sep 17 00:00:00 2001 From: Rob Blafford Date: Wed, 31 Jan 2024 10:37:15 -0500 Subject: [PATCH] kafka/s/h: Wrap call to lexical_cast in try block - 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: #16281 (cherry picked from commit 63efdf2b7a4c843751d52a74dd21971204971744) --- .../kafka/server/handlers/configs/config_utils.h | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/v/kafka/server/handlers/configs/config_utils.h b/src/v/kafka/server/handlers/configs/config_utils.h index c9cd74a069885..18f0b5ba82837 100644 --- a/src/v/kafka/server/handlers/configs/config_utils.h +++ b/src/v/kafka/server/handlers/configs/config_utils.h @@ -326,13 +326,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(*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(*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; } }