summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2020-07-22 10:51:00 +0200
committerThomas Haller <thaller@redhat.com>2020-07-23 15:29:22 +0200
commit1e870c675d09f997156cf6771281ccb5a7c7cf10 (patch)
tree56c908f196323fa533bf4d799eef55e1fefab9f0
parente9b84221de7d8fe0aae39f0946d1c1473bc45949 (diff)
downloadNetworkManager-1e870c675d09f997156cf6771281ccb5a7c7cf10.tar.gz
shared: avoid heap allocation for temporary string in nm_utils_parse_inaddr_prefix_bin()
-rw-r--r--shared/nm-glib-aux/nm-shared-utils.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/shared/nm-glib-aux/nm-shared-utils.c b/shared/nm-glib-aux/nm-shared-utils.c
index ee917fdf6e..f7ae5b88de 100644
--- a/shared/nm-glib-aux/nm-shared-utils.c
+++ b/shared/nm-glib-aux/nm-shared-utils.c
@@ -965,7 +965,7 @@ nm_utils_parse_inaddr_prefix_bin (int addr_family,
slash = strchr (text, '/');
if (slash)
- addrstr = addrstr_free = g_strndup (text, slash - text);
+ addrstr = nm_strndup_a (300, text, slash - text, &addrstr_free);
else
addrstr = text;
@@ -975,9 +975,12 @@ nm_utils_parse_inaddr_prefix_bin (int addr_family,
if (slash) {
/* For IPv4, `ip addr add` supports the prefix-length as a netmask. We don't
* do that. */
- prefix = _nm_utils_ascii_str_to_int64 (slash + 1, 10,
+ prefix = _nm_utils_ascii_str_to_int64 (&slash[1],
+ 10,
0,
- addr_family == AF_INET ? 32 : 128,
+ addr_family == AF_INET
+ ? 32
+ : 128,
-1);
if (prefix == -1)
return FALSE;