diff options
author | Gerald Combs <gerald@wireshark.org> | 2015-03-19 15:33:39 -0700 |
---|---|---|
committer | Gerald Combs <gerald@wireshark.org> | 2015-03-19 23:28:40 +0000 |
commit | 751df4e1fdb29f00c50ec48186b896b79395ad24 (patch) | |
tree | e4eb4fdfb1b683cde7d289f27a37a8631e5b77e5 /ui/capture_ui_utils.c | |
parent | bc06ca20ca4ca31d29212a4ada12ecd00789e3c3 (diff) |
Try to fix interface property fetching.
Use g_strdup instead of calculating string lengths manually. Return NULL
for empty strings, otherwise lo0 shows up as ": lo0" instead of
"Loopback: lo0" here.
Change-Id: I143aa5e12c9512b7a9f4729b62b353c13ee3635a
Reviewed-on: https://code.wireshark.org/review/7764
Reviewed-by: Gerald Combs <gerald@wireshark.org>
Diffstat (limited to 'ui/capture_ui_utils.c')
-rw-r--r-- | ui/capture_ui_utils.c | 17 |
1 files changed, 6 insertions, 11 deletions
diff --git a/ui/capture_ui_utils.c b/ui/capture_ui_utils.c index a0f13d1bbd..f94afb6b3a 100644 --- a/ui/capture_ui_utils.c +++ b/ui/capture_ui_utils.c @@ -79,21 +79,16 @@ capture_dev_get_if_property(const gchar *pref, const gchar *if_name) break; } closing_parenp = strrchr(if_tokens[i], ')'); - if (closing_parenp == NULL) { - /* No closing parenthesis. Give up. */ + if (closing_parenp == NULL || closing_parenp <= opening_parenp) { + /* No closing parenthesis or invalid input. Give up. */ break; } *opening_parenp = '\0'; /* Split {name} from what follows */ + *closing_parenp = '\0'; /* Terminate {property} */ if (strcmp(if_tokens[i], if_name) == 0) { - /* - * Copy everything from opening_parenp + 1 to closing_parenp - 1. - * That requires (closing_parenp - 1) - (opening_parenp + 1) + 1 - * bytes, including the trailing '\0', so that's - * (closing_parenp - opening_parenp) - 1. - */ - property = (gchar *)g_malloc(closing_parenp - opening_parenp - 1); - memcpy(property, opening_parenp + 1, closing_parenp - opening_parenp - 1); - property[closing_parenp - opening_parenp - 1] = '\0'; + if (strlen(opening_parenp + 1) > 0) { + property = g_strdup(opening_parenp + 1); + } break; } } |