From dd0109ee281e0392d8e53af34ef8462d8c6f9577 Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Thu, 26 Jun 2008 19:33:13 +0000 Subject: [PATCH] 2008-06-26 Dan Williams Patch from David Cantrell * Use inet_ntop() and inet_pton() everwhere and check for errors git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@3777 4912f4e0-d625-0410-9fb7-b9a5a253dbdc --- ChangeLog | 6 +++ libnm-glib/libnm-glib-test.c | 13 +++++-- libnm-util/nm-utils.c | 16 ++++++-- src/autoip.c | 38 ++++++++++++++++--- src/backends/NetworkManagerSuSE.c | 10 ++++- src/dhcp-manager/nm-dhcp-manager.c | 14 +++---- src/named-manager/nm-named-manager.c | 4 +- src/vpn-manager/nm-vpn-connection.c | 11 +++++- system-settings/plugins/ifcfg-fedora/reader.c | 2 +- system-settings/plugins/ifcfg-suse/parser.c | 4 +- system-settings/plugins/keyfile/writer.c | 36 +++++++++++++++--- test/nm-dhcp-opt-test.c | 9 ++++- test/nm-tool.c | 12 ++++-- .../src/nm-openvpn-service-openvpn-helper.c | 10 ++--- vpn-daemons/openvpn/src/nm-openvpn-service.c | 3 +- vpn-daemons/pptp/src/nm-ppp-starter.c | 12 +++++- .../vpnc/src/nm-vpnc-service-vpnc-helper.c | 8 ++-- 17 files changed, 162 insertions(+), 46 deletions(-) diff --git a/ChangeLog b/ChangeLog index 45fe96de58..cfdbfdf283 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2008-06-26 Dan Williams + + Patch from David Cantrell + + * Use inet_ntop() and inet_pton() everwhere and check for errors + 2008-06-26 Dan Williams * Update FSF address in license headers (Michael Biebl ) diff --git a/libnm-glib/libnm-glib-test.c b/libnm-glib/libnm-glib-test.c index f4c1242a55..3d6719203e 100644 --- a/libnm-glib/libnm-glib-test.c +++ b/libnm-glib/libnm-glib-test.c @@ -1,5 +1,6 @@ #include #include +#include #include #include @@ -47,13 +48,19 @@ test_get_state (NMClient *client) static gchar * ip4_address_as_string (guint32 ip) { + char buf[INET_ADDRSTRLEN+1]; struct in_addr tmp_addr; - gchar *ip_string; + memset (&buf, '\0', sizeof (buf)); tmp_addr.s_addr = ip; - ip_string = inet_ntoa (tmp_addr); - return g_strdup (ip_string); + if (inet_ntop (AF_INET, &tmp_addr, buf, INET_ADDRSTRLEN)) { + return g_strdup (buf); + } else { + nm_warning ("%s: error converting IP4 address 0x%X", + __func__, ntohl (tmp_addr.s_addr)); + return NULL; + } } static void diff --git a/libnm-util/nm-utils.c b/libnm-util/nm-utils.c index c9ba7f7948..a66b08d837 100644 --- a/libnm-util/nm-utils.c +++ b/libnm-util/nm-utils.c @@ -490,7 +490,9 @@ nm_utils_convert_uint_array_to_string (const GValue *src_value, GValue *dest_val memset (buf, 0, sizeof (buf)); addr.s_addr = g_array_index (array, guint32, i++); - inet_ntop (AF_INET, &addr, buf, INET_ADDRSTRLEN); + if (!inet_ntop (AF_INET, &addr, buf, INET_ADDRSTRLEN)) + nm_warning ("%s: error converting IP4 address 0x%X", + __func__, ntohl (addr.s_addr)); g_string_append_printf (printable, "%u (%s)", addr.s_addr, buf); } g_string_append_c (printable, ']'); @@ -528,13 +530,17 @@ nm_utils_convert_ip4_addr_struct_array_to_string (const GValue *src_value, GValu memset (buf, 0, sizeof (buf)); addr.s_addr = g_array_index (array, guint32, 0); - inet_ntop (AF_INET, &addr, buf, INET_ADDRSTRLEN); + if (!inet_ntop (AF_INET, &addr, buf, INET_ADDRSTRLEN)) + nm_warning ("%s: error converting IP4 address 0x%X", + __func__, ntohl (addr.s_addr)); g_string_append_printf (printable, "ip = %s", buf); g_string_append (printable, ", "); memset (buf, 0, sizeof (buf)); addr.s_addr = g_array_index (array, guint32, 1); - inet_ntop (AF_INET, &addr, buf, INET_ADDRSTRLEN); + if (!inet_ntop (AF_INET, &addr, buf, INET_ADDRSTRLEN)) + nm_warning ("%s: error converting IP4 address 0x%X", + __func__, ntohl (addr.s_addr)); g_string_append_printf (printable, "mask = %s", buf); if (array->len > 2) { @@ -542,7 +548,9 @@ nm_utils_convert_ip4_addr_struct_array_to_string (const GValue *src_value, GValu memset (buf, 0, sizeof (buf)); addr.s_addr = g_array_index (array, guint32, 2); - inet_ntop (AF_INET, &addr, buf, INET_ADDRSTRLEN); + if (!inet_ntop (AF_INET, &addr, buf, INET_ADDRSTRLEN)) + nm_warning ("%s: error converting IP4 address 0x%X", + __func__, ntohl (addr.s_addr)); g_string_append_printf (printable, "gw = %s", buf); } diff --git a/src/autoip.c b/src/autoip.c index d081e0add0..93ac1fa6f7 100644 --- a/src/autoip.c +++ b/src/autoip.c @@ -214,6 +214,9 @@ gboolean get_autoip (NMDevice *dev, struct in_addr *out_ip) int nannounce = 0; gboolean success = FALSE; const char *iface; + char buf[INET_ADDRSTRLEN+1]; + + memset(&buf, '\0', sizeof (buf)); g_return_val_if_fail (dev != NULL, FALSE); g_return_val_if_fail (out_ip != NULL, FALSE); @@ -262,7 +265,12 @@ gboolean get_autoip (NMDevice *dev, struct in_addr *out_ip) if (nprobes < PROBE_NUM) { - nm_info ("autoip: Sending probe #%d for IP address %s.", nprobes, inet_ntoa (ip)); + if (!inet_ntop (AF_INET, &ip, buf, INET_ADDRSTRLEN)) { + nm_warning ("%s: error converting IP4 address 0x%X", + __func__, ntohl (ip.s_addr)); + continue; + } + nm_info ("autoip: Sending probe #%d for IP address %s.", nprobes, buf); arp (fd, &saddr, ARPOP_REQUEST, &addr, null_ip, &null_addr, ip); nprobes++; gettimeofday (&timeout, NULL); @@ -284,7 +292,12 @@ gboolean get_autoip (NMDevice *dev, struct in_addr *out_ip) } else if (nannounce < ANNOUNCE_NUM) { - nm_info ("autoip: Sending announce #%d for IP address %s.", nannounce, inet_ntoa (ip)); + if (!inet_ntop (AF_INET, &ip, buf, INET_ADDRSTRLEN)) { + nm_warning ("%s: error converting IP4 address 0x%X", + __func__, ntohl (ip.s_addr)); + continue; + } + nm_info ("autoip: Sending announce #%d for IP address %s.", nannounce, buf); arp (fd, &saddr, ARPOP_REQUEST, &addr, ip, &addr, ip); nannounce++; gettimeofday (&timeout, NULL); @@ -319,10 +332,20 @@ gboolean get_autoip (NMDevice *dev, struct in_addr *out_ip) { struct in_addr a; memcpy (&(a.s_addr), &(p.sInaddr), sizeof (a.s_addr)); - nm_warning (" source = %s %02X:%02X:%02X:%02X:%02X:%02X, ", inet_ntoa (a), + if (!inet_ntop (AF_INET, &a, buf, INET_ADDRSTRLEN)) { + nm_warning ("%s: error converting IP4 address 0x%X", + __func__, ntohl (a.s_addr)); + continue; + } + nm_warning (" source = %s %02X:%02X:%02X:%02X:%02X:%02X, ", buf, p.sHaddr[0], p.sHaddr[1], p.sHaddr[2], p.sHaddr[3], p.sHaddr[4], p.sHaddr[5]); memcpy (&(a.s_addr), &(p.tInaddr), sizeof (a.s_addr)); - nm_warning (" target = %s %02X:%02X:%02X:%02X:%02X:%02X\n", inet_ntoa (a), + if (!inet_ntop (AF_INET, &a, buf, INET_ADDRSTRLEN)) { + nm_warning ("%s: error converting IP4 address 0x%X", + __func__, ntohl (a.s_addr)); + continue; + } + nm_warning (" target = %s %02X:%02X:%02X:%02X:%02X:%02X\n", buf, p.tHaddr[0], p.tHaddr[1], p.tHaddr[2], p.tHaddr[3], p.tHaddr[4], p.tHaddr[5]); } #endif @@ -333,7 +356,12 @@ gboolean get_autoip (NMDevice *dev, struct in_addr *out_ip) && (memcmp (&addr, &p.tHaddr, ETH_ALEN) != 0)) { #ifdef ARP_DEBUG - nm_warning ("autoip: (%s) ARP conflict for IP address %s.\n", iface, inet_ntoa(ip)); + if (!inet_ntop (AF_INET, &ip, buf, INET_ADDRSTRLEN)) { + nm_warning ("%s: error converting IP4 address 0x%X", + __func__, ntohl (ip.s_addr)); + continue; + } + nm_warning ("autoip: (%s) ARP conflict for IP address %s.\n", iface, buf); #endif /* Ok, start all over again */ diff --git a/src/backends/NetworkManagerSuSE.c b/src/backends/NetworkManagerSuSE.c index 3c94524b49..c6f2a0beab 100644 --- a/src/backends/NetworkManagerSuSE.c +++ b/src/backends/NetworkManagerSuSE.c @@ -106,6 +106,9 @@ void nm_system_activate_nis (NMIP4Config *config) struct in_addr temp_addr; int i; FILE *ypconf = NULL; + char buf[INET_ADDRSTRLEN+1]; + + memset (&buf, '\0', sizeof (buf)); g_return_if_fail (config != NULL); @@ -145,7 +148,12 @@ void nm_system_activate_nis (NMIP4Config *config) fprintf (ypconf, "# generated by NetworkManager, do not edit!\n\n"); for (i = 0; i < num_nis_servers; i++) { temp_addr.s_addr = nm_ip4_config_get_nis_server (config, i); - fprintf (ypconf, "domain %s server %s\n", nis_domain, inet_ntoa (temp_addr)); + + if (!inet_ntop (AF_INET, &temp_addr, buf, INET_ADDRSTRLEN)) + nm_warning ("%s: error converting IP4 address 0x%X", + __func__, ntohl (tempaddr.s_addr)); + else + fprintf (ypconf, "domain %s server %s\n", nis_domain, buf); } fprintf (ypconf, "\n"); fclose (ypconf); diff --git a/src/dhcp-manager/nm-dhcp-manager.c b/src/dhcp-manager/nm-dhcp-manager.c index 6ebfe2cbf6..cc5844cdfc 100644 --- a/src/dhcp-manager/nm-dhcp-manager.c +++ b/src/dhcp-manager/nm-dhcp-manager.c @@ -889,20 +889,20 @@ nm_dhcp_manager_get_ip4_config (NMDHCPManager *manager, } str = g_hash_table_lookup (device->options, "new_ip_address"); - if (str && inet_aton (str, &tmp_addr)) { + if (str && (inet_pton (AF_INET, str, &tmp_addr) > 0)) { addr->address = tmp_addr.s_addr; nm_info (" address %s", str); } else goto error; str = g_hash_table_lookup (device->options, "new_subnet_mask"); - if (str && inet_aton (str, &tmp_addr)) { + if (str && (inet_pton (AF_INET, str, &tmp_addr) > 0)) { addr->netmask = tmp_addr.s_addr; nm_info (" netmask %s", str); } str = g_hash_table_lookup (device->options, "new_routers"); - if (str && inet_aton (str, &tmp_addr)) { + if (str && (inet_pton (AF_INET, str, &tmp_addr) > 0)) { addr->gateway = tmp_addr.s_addr; nm_info(" gateway %s", str); } @@ -922,7 +922,7 @@ nm_dhcp_manager_get_ip4_config (NMDHCPManager *manager, char **s; for (s = searches; *s; s++) { - if (inet_aton (*s, &tmp_addr)) { + if (inet_pton (AF_INET, *s, &tmp_addr) > 0) { nm_ip4_config_add_nameserver (ip4_config, tmp_addr.s_addr); nm_info (" nameserver '%s'", *s); } else @@ -967,7 +967,7 @@ nm_dhcp_manager_get_ip4_config (NMDHCPManager *manager, char **s; for (s = searches; *s; s++) { - if (inet_aton (*s, &tmp_addr)) { + if (inet_pton (AF_INET, *s, &tmp_addr) > 0) { nm_ip4_config_add_nis_server (ip4_config, tmp_addr.s_addr); nm_info (" nis server '%s'", *s); } else @@ -987,11 +987,11 @@ nm_dhcp_manager_get_ip4_config (NMDHCPManager *manager, struct in_addr rt_addr; struct in_addr rt_route; - if (inet_aton (*s, &rt_addr) == 0) { + if (inet_pton (AF_INET, *s, &rt_addr) <= 0) { nm_warning ("DHCP provided invalid static route address: '%s'", *s); continue; } - if (inet_aton (*(s + 1), &rt_route) == 0) { + if (inet_pton (AF_INET, *(s + 1), &rt_route) <= 0) { nm_warning ("DHCP provided invalid static route gateway: '%s'", *(s + 1)); continue; } diff --git a/src/named-manager/nm-named-manager.c b/src/named-manager/nm-named-manager.c index ac3622f1be..0162ea9657 100644 --- a/src/named-manager/nm-named-manager.c +++ b/src/named-manager/nm-named-manager.c @@ -108,7 +108,9 @@ compute_nameservers (NMIP4Config *config) if (!buf) continue; - inet_ntop (AF_INET, &addr, buf, ADDR_BUF_LEN); + if (!inet_ntop (AF_INET, &addr, buf, ADDR_BUF_LEN)) + nm_warning ("%s: error converting IP4 address 0x%X", + __func__, ntohl (addr.s_addr)); if (i == 3) { g_string_append (str, "\n# "); diff --git a/src/vpn-manager/nm-vpn-connection.c b/src/vpn-manager/nm-vpn-connection.c index d923b497d8..a75937046f 100644 --- a/src/vpn-manager/nm-vpn-connection.c +++ b/src/vpn-manager/nm-vpn-connection.c @@ -261,9 +261,18 @@ static const char * ip_address_to_string (guint32 numeric) { struct in_addr temp_addr; + char buf[INET_ADDRSTRLEN+1]; + memset (&buf, '\0', sizeof (buf)); temp_addr.s_addr = numeric; - return inet_ntoa (temp_addr); + + if (inet_ntop (AF_INET, &temp_addr, buf, INET_ADDRSTRLEN)) { + return g_strdup (buf); + } else { + nm_warning ("%s: error converting IP4 address 0x%X", + __func__, ntohl (temp_addr.s_addr)); + return NULL; + } } static void diff --git a/system-settings/plugins/ifcfg-fedora/reader.c b/system-settings/plugins/ifcfg-fedora/reader.c index 8055936772..fdf1404b39 100644 --- a/system-settings/plugins/ifcfg-fedora/reader.c +++ b/system-settings/plugins/ifcfg-fedora/reader.c @@ -137,7 +137,7 @@ get_one_ip4_addr (shvarFile *ifcfg, if (!value) return; - if (inet_pton (AF_INET, value, &ip4_addr)) + if (inet_pton (AF_INET, value, &ip4_addr) > 0) *out_addr = ip4_addr.s_addr; else { g_set_error (error, ifcfg_plugin_error_quark (), 0, diff --git a/system-settings/plugins/ifcfg-suse/parser.c b/system-settings/plugins/ifcfg-suse/parser.c index 7749aaa3e8..65db38d89c 100644 --- a/system-settings/plugins/ifcfg-suse/parser.c +++ b/system-settings/plugins/ifcfg-suse/parser.c @@ -141,7 +141,7 @@ make_ip4_setting (shvarFile *ifcfg) pieces = g_strsplit (str, "/", 2); - if (inet_pton (AF_INET, pieces[0], &ip4_addr)) { + if (inet_pton (AF_INET, pieces[0], &ip4_addr) > 0) { tmp.address = ip4_addr.s_addr; if (g_strv_length (pieces) == 2) @@ -166,7 +166,7 @@ make_ip4_setting (shvarFile *ifcfg) if (str) { struct in_addr mask_addr; - if (inet_pton (AF_INET, str, &mask_addr)) + if (inet_pton (AF_INET, str, &mask_addr) > 0) tmp.netmask = mask_addr.s_addr; else { g_warning ("Ignoring invalid IP4 addres: invalid netmask: '%s'", str); diff --git a/system-settings/plugins/keyfile/writer.c b/system-settings/plugins/keyfile/writer.c index 8a994e8af5..5f78509d5f 100644 --- a/system-settings/plugins/keyfile/writer.c +++ b/system-settings/plugins/keyfile/writer.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include @@ -36,7 +37,13 @@ write_array_of_uint (GKeyFile *file, struct in_addr addr; addr.s_addr = g_array_index (array, guint32, i); - list[i] = g_strdup (inet_ntop (AF_INET, &addr, buf, sizeof (buf))); + if (!inet_ntop (AF_INET, &addr, buf, sizeof (buf))) { + nm_warning ("%s: error converting IP4 address 0x%X", + __func__, ntohl (addr.s_addr)); + list[i] = NULL; + } else { + list[i] = g_strdup (buf); + } } g_key_file_set_string_list (file, setting->name, key, (const char **) list, array->len); @@ -81,14 +88,33 @@ write_array_of_array_of_uint (GKeyFile *file, char *key_name; addr.s_addr = g_array_index (tuple, guint32, 0); - list[0] = g_strdup (inet_ntop (AF_INET, &addr, buf, sizeof (buf))); + if (!inet_ntop (AF_INET, &addr, buf, sizeof (buf))) { + nm_warning ("%s: error converting IP4 address 0x%X", + __func__, ntohl (addr.s_addr)); + list[0] = NULL; + } else { + list[0] = g_strdup (buf); + } addr.s_addr = g_array_index (tuple, guint32, 1); - list[1] = g_strdup (inet_ntop (AF_INET, &addr, buf, sizeof (buf))); + if (!inet_ntop (AF_INET, &addr, buf, sizeof (buf))) { + nm_warning ("%s: error converting IP4 address 0x%X", + __func__, ntohl (addr.s_addr)); + list[1] = NULL; + } else { + list[1] = g_strdup (buf); + } addr.s_addr = g_array_index (tuple, guint32, 2); - if (addr.s_addr) - list[2] = g_strdup (inet_ntop (AF_INET, &addr, buf, sizeof (buf))); + if (addr.s_addr) { + if (!inet_ntop (AF_INET, &addr, buf, sizeof (buf))) { + nm_warning ("%s: error converting IP4 address 0x%X", + __func__, ntohl (addr.s_addr)); + list[2] = NULL; + } else { + list[2] = g_strdup (buf); + } + } key_name = g_strdup_printf ("address%d", j + 1); g_key_file_set_string_list (file, setting->name, key_name, (const char **) list, list[2] ? 3 : 2); diff --git a/test/nm-dhcp-opt-test.c b/test/nm-dhcp-opt-test.c index 5bfc6d3032..3f7667c043 100644 --- a/test/nm-dhcp-opt-test.c +++ b/test/nm-dhcp-opt-test.c @@ -155,6 +155,9 @@ void print_array (DBusConnection *connection, int opt) const char *name = NULL; int opt_type = -1; unsigned int foo; + char buf[INET_ADDRSTRLEN+1]; + + memset (&buf, '\0', sizeof (buf)); ret = call_nm_method (connection, "getName", opt, FALSE, DBUS_TYPE_STRING, (void *)(&name), NULL); if (ret != RETURN_SUCCESS) @@ -212,7 +215,11 @@ void print_array (DBusConnection *connection, int opt) break; case DBUS_TYPE_UINT32: in.s_addr = uint32[i]; - fprintf (stderr, "%u (%s)%s", uint32[i], inet_ntoa(in), last ? "" : ", "); + if (!inet_ntop (AF_INET, &in, buf, INET_ADDRSTRLEN)) + nm_warning ("%s: error converting IP4 address 0x%X", + __func__, ntohl (in.s_addr)); + else + fprintf (stderr, "%u (%s)%s", uint32[i], buf, last ? "" : ", "); break; case DBUS_TYPE_STRING: fprintf (stderr, "'%s'%s", string[i], last ? "" : ", "); diff --git a/test/nm-tool.c b/test/nm-tool.c index c8f2fce2b2..47d73d6b15 100644 --- a/test/nm-tool.c +++ b/test/nm-tool.c @@ -162,12 +162,18 @@ static gchar * ip4_address_as_string (guint32 ip) { struct in_addr tmp_addr; - gchar *ip_string; + char buf[INET_ADDRSTRLEN+1]; + memset (&buf, '\0', sizeof (buf)); tmp_addr.s_addr = ip; - ip_string = inet_ntoa (tmp_addr); - return g_strdup (ip_string); + if (inet_ntop (AF_INET, &tmp_addr, buf, INET_ADDRSTRLEN)) { + return g_strdup (buf); + } else { + nm_warning ("%s: error converting IP4 address 0x%X", + __func__, ntohl (tmp_addr.s_addr)); + return NULL; + } } static const char * diff --git a/vpn-daemons/openvpn/src/nm-openvpn-service-openvpn-helper.c b/vpn-daemons/openvpn/src/nm-openvpn-service-openvpn-helper.c index 72fa1f2fd3..a2aabdf32a 100644 --- a/vpn-daemons/openvpn/src/nm-openvpn-service-openvpn-helper.c +++ b/vpn-daemons/openvpn/src/nm-openvpn-service-openvpn-helper.c @@ -135,7 +135,7 @@ addr_to_gvalue (const char *str) if (!str || strlen (str) < 1) return NULL; - if (!inet_aton (str, &temp_addr)) + if (inet_pton (AF_INET, str, &temp_addr) <= 0) return NULL; val = g_slice_new0 (GValue); @@ -164,7 +164,7 @@ parse_addr_list (GValue *value_array, const char *str) split = g_strsplit (str, " ", -1); for (i = 0; split[i]; i++) { - if (inet_aton (split[i], &temp_addr)) + if (inet_pton (AF_INET, split[i], &temp_addr) > 0) g_array_append_val (array, temp_addr.s_addr); } @@ -203,21 +203,21 @@ get_routes (void) if (!tmp || strlen (tmp) < 1) break; - if (inet_aton (tmp, &network) != 0) { + if (inet_pton (AF_INET, tmp, &network) <= 0) { nm_warning ("Ignoring invalid static route address '%s'", tmp ? tmp : "NULL"); continue; } snprintf (buf, BUFLEN, "route_netmask_%d", i); tmp = getenv (buf); - if (!tmp || inet_aton (tmp, &netmask) != 0) { + if (!tmp || inet_pton (AF_INET, tmp, &netmask) <= 0) { nm_warning ("Ignoring invalid static route netmask '%s'", tmp ? tmp : "NULL"); continue; } snprintf (buf, BUFLEN, "route_gateway_%d", i); tmp = getenv (buf); - if (!tmp || inet_aton (tmp, &gateway) != 0) { + if (!tmp || inet_pton (AF_INET, tmp, &gateway) <= 0) { nm_warning ("Ignoring invalid static route gateway '%s'", tmp ? tmp : "NULL"); continue; } diff --git a/vpn-daemons/openvpn/src/nm-openvpn-service.c b/vpn-daemons/openvpn/src/nm-openvpn-service.c index 7be6a8bb77..e3a7b40dba 100644 --- a/vpn-daemons/openvpn/src/nm-openvpn-service.c +++ b/vpn-daemons/openvpn/src/nm-openvpn-service.c @@ -244,7 +244,8 @@ nm_openvpn_connect_timer_cb (gpointer data) return FALSE; serv_addr.sin_family = AF_INET; - inet_aton ("127.0.0.1", &(serv_addr.sin_addr)); + if (inet_pton (AF_INET, "127.0.0.1", &(serv_addr.sin_addr)) <= 0) + nm_warning ("%s: could not convert 127.0.0.1", __func__); serv_addr.sin_port = htons (1194); connected = (connect (socket_fd, (struct sockaddr *) &serv_addr, sizeof (serv_addr)) == 0); diff --git a/vpn-daemons/pptp/src/nm-ppp-starter.c b/vpn-daemons/pptp/src/nm-ppp-starter.c index 411dc540c3..a699d2b8f4 100644 --- a/vpn-daemons/pptp/src/nm-ppp-starter.c +++ b/vpn-daemons/pptp/src/nm-ppp-starter.c @@ -442,7 +442,9 @@ static gint nm_ppp_get_cmdline_pptp (NmPPPData *data, char **data_items, const i int i = 0; struct hostent *hostinfo = NULL; char * pppd_pty = NULL; + char buf[INET_ADDRSTRLEN+1]; + memset (&buf, '\0', sizeof (buf)); /* Find pptp */ pptp_binary = pptp_binary_paths; @@ -466,7 +468,10 @@ static gint nm_ppp_get_cmdline_pptp (NmPPPData *data, char **data_items, const i return -1; } data -> ip4_vpn_gateway = *(struct in_addr*)(hostinfo->h_addr_list[0]); - data -> str_ip4_vpn_gateway = g_strdup( inet_ntoa( data -> ip4_vpn_gateway ) ); + + if ( !inet_ntop (AF_INET, &data -> ip4_vpn_gateway, buf, INET_ADDRSTRLEN)) + data -> str_ip4_vpn_gateway = NULL; + data -> str_ip4_vpn_gateway = g_strdup( buf ); pppd_pty = g_strdup_printf ("%s %s --nolaunchpppd", (*pptp_binary), data->str_ip4_vpn_gateway); @@ -510,7 +515,10 @@ static gint nm_ppp_get_cmdline_dialup (NmPPPData *data, char **data_items, const // return -1; // } // data -> ip4_vpn_gateway = *(struct in_addr*)(hostinfo->h_addr_list[0]); -// data -> str_ip4_vpn_gateway = g_strdup( inet_ntoa( data -> ip4_vpn_gateway ) ); +// +// if ( !inet_ntop (AF_INET, &data -> ip4_vpn_gateway, buf, INET_ADDRSTRLEN)) +// data -> str_ip4_gateway = NULL; +// data -> str_ip4_vpn_gateway = g_strdup( buf ); // // pppd_pty = g_strdup_printf ("%s %s --nolaunchpppd", (*pptp_binary), data->str_ip4_vpn_gateway); // diff --git a/vpn-daemons/vpnc/src/nm-vpnc-service-vpnc-helper.c b/vpn-daemons/vpnc/src/nm-vpnc-service-vpnc-helper.c index a9a4892a1d..5490db29c1 100644 --- a/vpn-daemons/vpnc/src/nm-vpnc-service-vpnc-helper.c +++ b/vpn-daemons/vpnc/src/nm-vpnc-service-vpnc-helper.c @@ -141,7 +141,7 @@ addr_to_gvalue (const char *str) if (!str || strlen (str) < 1) return NULL; - if (!inet_aton (str, &temp_addr)) + if (inet_pton (AF_INET, str, &temp_addr) <= 0) return NULL; return uint_to_gvalue (temp_addr.s_addr); @@ -167,7 +167,7 @@ addr_list_to_gvalue (const char *str) for (i = 0; split[i]; i++) { struct in_addr addr; - if (inet_aton (split[i], &addr)) { + if (inet_pton (AF_INET, split[i], &addr) > 0) { g_array_append_val (array, addr.s_addr); } else { g_strfreev (split); @@ -215,14 +215,14 @@ get_routes (void) snprintf (buf, BUFLEN, "CISCO_SPLIT_INC_%d_ADDR", i); tmp = getenv (buf); - if (!tmp || inet_aton (tmp, &network) != 0) { + if (!tmp || inet_pton (AF_INET, tmp, &network) <= 0) { nm_warning ("Ignoring invalid static route address '%s'", tmp ? tmp : "NULL"); continue; } snprintf (buf, BUFLEN, "CISCO_SPLIT_INC_%d_MASK", i); tmp = getenv (buf); - if (!tmp || inet_aton (tmp, &netmask) != 0) { + if (!tmp || inet_pton (AF_INET, tmp, &netmask) <= 0) { nm_warning ("Ignoring invalid static route netmask '%s'", tmp ? tmp : "NULL"); continue; }