From 46e3c23d857c8349f8c7f3d583005398310f4308 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 19 Sep 2022 08:27:13 +0200 Subject: [PATCH] bond: use _nm_setting_bond_opt_value_as_intbool() in _platform_lnk_bond_init_from_setting() Previously, we used _nm_utils_ascii_str_to_bool(). That can accept any kind of input (like "true"), so one might think that this is better to use on user-input. However, NMSettingBond already validates the these options are integers (either "0" or "1"). So a value like "true" could never be here. Use _nm_setting_bond_opt_value_as_intbool() because that asserts that the option if of the expected type (integer). (cherry picked from commit b1a72d0f212f0a7213d39a982ffa7540f27c1eeb) --- src/core/devices/nm-device-bond.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/core/devices/nm-device-bond.c b/src/core/devices/nm-device-bond.c index c854701f6a..3e083de461 100644 --- a/src/core/devices/nm-device-bond.c +++ b/src/core/devices/nm-device-bond.c @@ -399,6 +399,7 @@ _platform_lnk_bond_init_from_setting(NMSettingBond *s_bond, NMPlatformLnkBond *p #define _v_u8(s_bond, opt) _nm_setting_bond_opt_value_as_u8((s_bond), (opt)) #define _v_u16(s_bond, opt) _nm_setting_bond_opt_value_as_u16((s_bond), (opt)) #define _v_u32(s_bond, opt) _nm_setting_bond_opt_value_as_u32((s_bond), (opt)) +#define _v_intbool(s_bond, opt) _nm_setting_bond_opt_value_as_intbool((s_bond), (opt)) *props = (NMPlatformLnkBond){ .mode = _v_fcn(_nm_setting_bond_mode_from_string, s_bond, NM_SETTING_BOND_OPTION_MODE), @@ -437,21 +438,14 @@ _platform_lnk_bond_init_from_setting(NMSettingBond *s_bond, NMPlatformLnkBond *p .ad_select = _v_fcn(_nm_setting_bond_ad_select_from_string, s_bond, NM_SETTING_BOND_OPTION_AD_SELECT), + .use_carrier = _v_intbool(s_bond, NM_SETTING_BOND_OPTION_USE_CARRIER), + .tlb_dynamic_lb = _v_intbool(s_bond, NM_SETTING_BOND_OPTION_TLB_DYNAMIC_LB), }; nm_ether_addr_from_string( &props->ad_actor_system, nm_setting_bond_get_option_normalized(s_bond, NM_SETTING_BOND_OPTION_AD_ACTOR_SYSTEM)); - opt_value = nm_setting_bond_get_option_normalized(s_bond, NM_SETTING_BOND_OPTION_USE_CARRIER); - if (opt_value != NULL) - props->use_carrier = _nm_utils_ascii_str_to_bool(opt_value, FALSE); - - opt_value = - nm_setting_bond_get_option_normalized(s_bond, NM_SETTING_BOND_OPTION_TLB_DYNAMIC_LB); - if (opt_value != NULL) - props->tlb_dynamic_lb = _nm_utils_ascii_str_to_bool(opt_value, FALSE); - opt_value = nm_setting_bond_get_option_normalized(s_bond, NM_SETTING_BOND_OPTION_ARP_IP_TARGET); if (opt_value != NULL) props->arp_ip_targets_num =