summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2021-07-16 09:36:49 +0200
committerThomas Haller <thaller@redhat.com>2021-07-19 09:04:49 +0200
commit17bdd3a40d7bc0bbba52ad333be4b3210fa3981a (patch)
tree1c6e2afdefdc895e2ed2fd3d5aba63e7a5646ef0
parentfc2f758af52bf5d39bd4a9b96c30345692971fdb (diff)
downloadNetworkManager-17bdd3a40d7bc0bbba52ad333be4b3210fa3981a.tar.gz
libnm: fix clearing parentheses in nm_utils_fixup_product_string()
Previously, once in_parent was TRUE it was never reset, thus the remainder of the string was cleared. That was most likely not intended. If the intent really was to clear all the remainder, then the code could have simply truncated the string at the first '('.
-rw-r--r--src/libnm-client-impl/nm-libnm-utils.c11
-rw-r--r--src/libnm-client-impl/tests/test-libnm.c54
2 files changed, 34 insertions, 31 deletions
diff --git a/src/libnm-client-impl/nm-libnm-utils.c b/src/libnm-client-impl/nm-libnm-utils.c
index 3cc88ef4d8..045dc6a5b7 100644
--- a/src/libnm-client-impl/nm-libnm-utils.c
+++ b/src/libnm-client-impl/nm-libnm-utils.c
@@ -160,14 +160,17 @@ _fixup_string(const char * desc,
p = q + 1;
}
- /* replace '_', ',', ASCII control characters and parentheses, with space. */
+ /* replace '_', ',', ASCII control characters and everything inside parentheses, with space. */
for (p = desc_full; p[0]; p++) {
if (*p == '(')
in_paren = TRUE;
- if (NM_IN_SET(*p, '_', ',') || *p < ' ' || in_paren)
- *p = ' ';
- if (*p == ')')
+ else if (*p == ')')
in_paren = FALSE;
+ else if (NM_IN_SET(*p, '_', ',') || *p < ' ' || in_paren) {
+ /* pass */
+ } else
+ continue;
+ *p = ' ';
}
/* Attempt to shorten ID by ignoring certain phrases */
diff --git a/src/libnm-client-impl/tests/test-libnm.c b/src/libnm-client-impl/tests/test-libnm.c
index c260aebed6..18bb09da9d 100644
--- a/src/libnm-client-impl/tests/test-libnm.c
+++ b/src/libnm-client-impl/tests/test-libnm.c
@@ -219,7 +219,7 @@ test_fixup_vendor_string(void)
T_DATA("Memorex", "Memorex"),
T_DATA("Micrel-Kendin", "Micrel-Kendin"),
T_DATA("Microchip Technology, Inc.", "Microchip"),
- T_DATA("Microcomputer Systems (M) Son", "Microcomputer"),
+ T_DATA("Microcomputer Systems (M) Son", "Microcomputer Son"),
T_DATA("Microsoft Corp.", "Microsoft"),
T_DATA("Microsoft Corporation", "Microsoft"),
T_DATA("Micro-Star International Co., Ltd. [MSI]", "MSI"),
@@ -594,11 +594,11 @@ test_fixup_product_string(void)
T_DATA("82599 Ethernet Controller Virtual Function", "82599 Virtual Function"),
T_DATA("82599 Virtual Function", "82599 Virtual Function"),
T_DATA("82801BA/BAM/CA/CAM Ethernet Controller", "82801BA/BAM/CA/CAM"),
- T_DATA("82801CAM (ICH3) PRO/100 VE Ethernet Controller", "82801CAM"),
- T_DATA("82801CAM (ICH3) PRO/100 VE (LOM) Ethernet Controller", "82801CAM"),
- T_DATA("82801CAM (ICH3) PRO/100 VM Ethernet Controller", "82801CAM"),
- T_DATA("82801CAM (ICH3) PRO/100 VM (KM) Ethernet Controller", "82801CAM"),
- T_DATA("82801CAM (ICH3) PRO/100 VM (LOM) Ethernet Controller", "82801CAM"),
+ T_DATA("82801CAM (ICH3) PRO/100 VE Ethernet Controller", "82801CAM PRO/100 VE"),
+ T_DATA("82801CAM (ICH3) PRO/100 VE (LOM) Ethernet Controller", "82801CAM PRO/100 VE"),
+ T_DATA("82801CAM (ICH3) PRO/100 VM Ethernet Controller", "82801CAM PRO/100 VM"),
+ T_DATA("82801CAM (ICH3) PRO/100 VM (KM) Ethernet Controller", "82801CAM PRO/100 VM"),
+ T_DATA("82801CAM (ICH3) PRO/100 VM (LOM) Ethernet Controller", "82801CAM PRO/100 VM"),
T_DATA("82801DB PRO/100 VE (CNR) Ethernet Controller", "82801DB PRO/100 VE"),
T_DATA("82801DB PRO/100 VE (LOM) Ethernet Controller", "82801DB PRO/100 VE"),
T_DATA("82801DB PRO/100 VE (MOB) Ethernet Controller", "82801DB PRO/100 VE"),
@@ -1009,25 +1009,25 @@ test_fixup_product_string(void)
T_DATA("Ethernet Adapter", NULL),
T_DATA("Ethernet adapter [U2L 100P-Y1]", "U2L 100P-Y1"),
T_DATA("Ethernet Adaptive Virtual Function", "Adaptive Virtual Function"),
- T_DATA("Ethernet Connection (2) I218-LM", NULL),
- T_DATA("Ethernet Connection (2) I218-V", NULL),
- T_DATA("Ethernet Connection (2) I219-LM", NULL),
- T_DATA("Ethernet Connection (2) I219-V", NULL),
- T_DATA("Ethernet Connection (3) I218-LM", NULL),
- T_DATA("Ethernet Connection (3) I218-V", NULL),
- T_DATA("Ethernet Connection (3) I219-LM", NULL),
- T_DATA("Ethernet Connection (4) I219-LM", NULL),
- T_DATA("Ethernet Connection (4) I219-V", NULL),
- T_DATA("Ethernet Connection (5) I219-LM", NULL),
- T_DATA("Ethernet Connection (5) I219-V", NULL),
- T_DATA("Ethernet Connection (6) I219-LM", NULL),
- T_DATA("Ethernet Connection (6) I219-V", NULL),
- T_DATA("Ethernet Connection (7) I219-LM", NULL),
- T_DATA("Ethernet Connection (7) I219-V", NULL),
- T_DATA("Ethernet Connection (8) I219-LM", NULL),
- T_DATA("Ethernet Connection (8) I219-V", NULL),
- T_DATA("Ethernet Connection (9) I219-LM", NULL),
- T_DATA("Ethernet Connection (9) I219-V", NULL),
+ T_DATA("Ethernet Connection (2) I218-LM", "I218-LM"),
+ T_DATA("Ethernet Connection (2 I218-V", NULL),
+ T_DATA("Ethernet Connection (2 I219-LM", NULL),
+ T_DATA("Ethernet Connection (2 I219-V", NULL),
+ T_DATA("Ethernet Connection (3) I218-LM", "I218-LM"),
+ T_DATA("Ethernet Connection (3) I218-V", "I218-V"),
+ T_DATA("Ethernet Connection (3 I219-LM", NULL),
+ T_DATA("Ethernet Connection (4 I219-LM", NULL),
+ T_DATA("Ethernet Connection (4 I219-V", NULL),
+ T_DATA("Ethernet Connection (5 I219-LM", NULL),
+ T_DATA("Ethernet Connection (5 I219-V", NULL),
+ T_DATA("Ethernet Connection (6 I219-LM", NULL),
+ T_DATA("Ethernet Connection (6 I219-V", NULL),
+ T_DATA("Ethernet Connection (7 I219-LM", NULL),
+ T_DATA("Ethernet Connection (7 I219-V", NULL),
+ T_DATA("Ethernet Connection (8 I219-LM", NULL),
+ T_DATA("Ethernet Connection (8 I219-V", NULL),
+ T_DATA("Ethernet Connection (9 I219-LM", NULL),
+ T_DATA("Ethernet Connection (9 I219-V", NULL),
T_DATA("Ethernet Connection I217-LM", "I217-LM"),
T_DATA("Ethernet Connection I217-V", "I217-V"),
T_DATA("Ethernet Connection I218-LM", "I218-LM"),
@@ -2160,12 +2160,12 @@ test_fixup_product_string(void)
"WLM-20U2/GN-1080"),
T_DATA("WLP-UC-AG300 Wireless LAN Adapter", "WLP-UC-AG300"),
T_DATA("WM168g 802.11bg Wireless Adapter [Intersil ISL3886]", "WM168g"),
- T_DATA("WN111(v2) RangeMax Next Wireless [Atheros AR9170+AR9101]", "WN111"),
+ T_DATA("WN111(v2) RangeMax Next Wireless [Atheros AR9170+AR9101]", "WN111 RangeMax Next"),
T_DATA("WNA1000M 802.11bgn [Realtek RTL8188CUS]", "WNA1000M"),
T_DATA("WNA1000Mv2 802.11bgn [Realtek RTL8188CUS?]", "WNA1000Mv2"),
T_DATA("WNA1000 Wireless-N 150 [Atheros AR9170+AR9101]", "WNA1000 150"),
T_DATA("WNA1100 Wireless-N 150 [Atheros AR9271]", "WNA1100 150"),
- T_DATA("WNA3100M(v1) Wireless-N 300 [Realtek RTL8192CU]", "WNA3100M"),
+ T_DATA("WNA3100M(v1) Wireless-N 300 [Realtek RTL8192CU]", "WNA3100M 300"),
T_DATA("WNDA3100v1 802.11abgn [Atheros AR9170+AR9104]", "WNDA3100v1"),
T_DATA("WNDA3200 802.11abgn Wireless Adapter [Atheros AR7010+AR9280]", "WNDA3200"),
T_DATA("WNDA4100 802.11abgn 3x3:3 [Ralink RT3573]", "WNDA4100"),