aboutsummaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2015-03-18 17:47:55 -0700
committerGuy Harris <guy@alum.mit.edu>2015-03-19 00:48:22 +0000
commitcb31cc61d7717848a47f65809f0e97a905ae9240 (patch)
tree7a3defc170674ccadc01b373854fd633b79fcd0f /ui
parentc691af8737e0ec1131843282eab3587a741f5a3d (diff)
Fix extracting of parameter.
We have to find the closing parenthesis before overwriting the opening parenthesis, otherwise the end of the string, from which strrchr() searches, is at the point where the opening parenthesis was. Fix incorrect arithmetic (-1 + -1 + 1 = -1, not 1). Change-Id: Ida47dd9670b36269eef28368aa845301a7185c3f Reviewed-on: https://code.wireshark.org/review/7747 Reviewed-by: Guy Harris <guy@alum.mit.edu>
Diffstat (limited to 'ui')
-rw-r--r--ui/capture_ui_utils.c18
1 files changed, 9 insertions, 9 deletions
diff --git a/ui/capture_ui_utils.c b/ui/capture_ui_utils.c
index 6e3bd6fe96..4db0ef6e96 100644
--- a/ui/capture_ui_utils.c
+++ b/ui/capture_ui_utils.c
@@ -78,22 +78,22 @@ capture_dev_get_if_property(const gchar *pref, const gchar *if_name)
/* No opening parenthesis. Give up. */
break;
}
+ closing_parenp = strrchr(if_tokens[i], ')');
+ if (closing_parenp == NULL) {
+ /* No closing parenthesis. Give up. */
+ break;
+ }
*opening_parenp = '\0'; /* Split {name} from what follows */
if (strcmp(if_tokens[i], if_name) == 0) {
- closing_parenp = strrchr(if_tokens[i], ')');
- if (closing_parenp == NULL) {
- /* No closing parenthesis. Give up. */
- break;
- }
/*
* 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.
+ * (closing_parenp - opening_parenp) - 1.
*/
- property = g_malloc(closing_parenp - opening_parenp + 1);
- memcpy(property, opening_parenp + 1, closing_parenp - opening_parenp);
- property[closing_parenp - opening_parenp] = '\0';
+ property = g_malloc(closing_parenp - opening_parenp - 1);
+ memcpy(property, opening_parenp + 1, closing_parenp - opening_parenp - 1);
+ property[closing_parenp - opening_parenp - 1] = '\0';
break;
}
}