ifcfg-rh: use _nm_utils_ascii_str_to_int64() instead of strtol()
This commit is contained in:
@@ -226,15 +226,12 @@ make_connection_setting (const char *file,
|
|||||||
|
|
||||||
value = svGetValue (ifcfg, "GATEWAY_PING_TIMEOUT", FALSE);
|
value = svGetValue (ifcfg, "GATEWAY_PING_TIMEOUT", FALSE);
|
||||||
if (value) {
|
if (value) {
|
||||||
long int tmp;
|
gint64 tmp;
|
||||||
guint32 timeout;
|
|
||||||
|
|
||||||
errno = 0;
|
tmp = _nm_utils_ascii_str_to_int64 (value, 10, 0, G_MAXINT32 - 1, -1);
|
||||||
tmp = strtol (value, NULL, 10);
|
if (tmp >= 0)
|
||||||
if (errno == 0 && tmp >= 0 && tmp < G_MAXINT32) {
|
g_object_set (s_con, NM_SETTING_CONNECTION_GATEWAY_PING_TIMEOUT, (guint) tmp, NULL);
|
||||||
timeout = (guint32) tmp;
|
else
|
||||||
g_object_set (s_con, NM_SETTING_CONNECTION_GATEWAY_PING_TIMEOUT, timeout, NULL);
|
|
||||||
} else
|
|
||||||
PARSE_WARNING ("invalid GATEWAY_PING_TIMEOUT time");
|
PARSE_WARNING ("invalid GATEWAY_PING_TIMEOUT time");
|
||||||
g_free (value);
|
g_free (value);
|
||||||
}
|
}
|
||||||
@@ -525,7 +522,8 @@ read_route_file_legacy (const char *filename, NMSettingIPConfig *s_ip4, GError *
|
|||||||
char **lines = NULL, **iter;
|
char **lines = NULL, **iter;
|
||||||
GRegex *regex_to1, *regex_to2, *regex_via, *regex_metric;
|
GRegex *regex_to1, *regex_to2, *regex_via, *regex_metric;
|
||||||
GMatchInfo *match_info;
|
GMatchInfo *match_info;
|
||||||
gint64 prefix_int, metric_int;
|
int prefix_int;
|
||||||
|
gint64 metric_int;
|
||||||
gboolean success = FALSE;
|
gboolean success = FALSE;
|
||||||
|
|
||||||
const char *pattern_empty = "^\\s*(\\#.*)?$";
|
const char *pattern_empty = "^\\s*(\\#.*)?$";
|
||||||
@@ -593,9 +591,8 @@ read_route_file_legacy (const char *filename, NMSettingIPConfig *s_ip4, GError *
|
|||||||
g_match_info_free (match_info);
|
g_match_info_free (match_info);
|
||||||
prefix_int = 32;
|
prefix_int = 32;
|
||||||
if (prefix) {
|
if (prefix) {
|
||||||
errno = 0;
|
prefix_int = _nm_utils_ascii_str_to_int64 (prefix, 10, 1, 32, -1);
|
||||||
prefix_int = strtol (prefix, NULL, 10);
|
if (prefix_int == -1) {
|
||||||
if (errno || prefix_int <= 0 || prefix_int > 32) {
|
|
||||||
g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION,
|
g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION,
|
||||||
"Invalid IP4 route destination prefix '%s'", prefix);
|
"Invalid IP4 route destination prefix '%s'", prefix);
|
||||||
g_free (prefix);
|
g_free (prefix);
|
||||||
@@ -625,9 +622,8 @@ read_route_file_legacy (const char *filename, NMSettingIPConfig *s_ip4, GError *
|
|||||||
metric_int = -1;
|
metric_int = -1;
|
||||||
if (g_match_info_matches (match_info)) {
|
if (g_match_info_matches (match_info)) {
|
||||||
metric = g_match_info_fetch (match_info, 1);
|
metric = g_match_info_fetch (match_info, 1);
|
||||||
errno = 0;
|
metric_int = _nm_utils_ascii_str_to_int64 (metric, 10, 0, G_MAXUINT32, -1);
|
||||||
metric_int = strtol (metric, NULL, 10);
|
if (metric_int == -1) {
|
||||||
if (errno || metric_int < 0) {
|
|
||||||
g_match_info_free (match_info);
|
g_match_info_free (match_info);
|
||||||
g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION,
|
g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION,
|
||||||
"Invalid IP4 route metric '%s'", metric);
|
"Invalid IP4 route metric '%s'", metric);
|
||||||
@@ -750,7 +746,8 @@ read_route6_file (const char *filename, NMSettingIPConfig *s_ip6, GError **error
|
|||||||
GRegex *regex_to1, *regex_to2, *regex_via, *regex_metric;
|
GRegex *regex_to1, *regex_to2, *regex_via, *regex_metric;
|
||||||
GMatchInfo *match_info;
|
GMatchInfo *match_info;
|
||||||
char *dest = NULL, *prefix = NULL, *next_hop = NULL, *metric = NULL;
|
char *dest = NULL, *prefix = NULL, *next_hop = NULL, *metric = NULL;
|
||||||
gint64 prefix_int, metric_int;
|
int prefix_int;
|
||||||
|
gint64 metric_int;
|
||||||
gboolean success = FALSE;
|
gboolean success = FALSE;
|
||||||
|
|
||||||
const char *pattern_empty = "^\\s*(\\#.*)?$";
|
const char *pattern_empty = "^\\s*(\\#.*)?$";
|
||||||
@@ -812,9 +809,8 @@ read_route6_file (const char *filename, NMSettingIPConfig *s_ip6, GError **error
|
|||||||
g_match_info_free (match_info);
|
g_match_info_free (match_info);
|
||||||
prefix_int = 128;
|
prefix_int = 128;
|
||||||
if (prefix) {
|
if (prefix) {
|
||||||
errno = 0;
|
prefix_int = _nm_utils_ascii_str_to_int64 (prefix, 10, 1, 128, -1);
|
||||||
prefix_int = strtol (prefix, NULL, 10);
|
if (prefix_int == -1) {
|
||||||
if (errno || prefix_int <= 0 || prefix_int > 128) {
|
|
||||||
g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION,
|
g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION,
|
||||||
"Invalid IP6 route destination prefix '%s'", prefix);
|
"Invalid IP6 route destination prefix '%s'", prefix);
|
||||||
g_free (dest);
|
g_free (dest);
|
||||||
@@ -848,9 +844,8 @@ read_route6_file (const char *filename, NMSettingIPConfig *s_ip6, GError **error
|
|||||||
metric_int = -1;
|
metric_int = -1;
|
||||||
if (g_match_info_matches (match_info)) {
|
if (g_match_info_matches (match_info)) {
|
||||||
metric = g_match_info_fetch (match_info, 1);
|
metric = g_match_info_fetch (match_info, 1);
|
||||||
errno = 0;
|
metric_int = _nm_utils_ascii_str_to_int64 (metric, 10, 0, G_MAXUINT32, -1);
|
||||||
metric_int = strtol (metric, NULL, 10);
|
if (metric_int == -1) {
|
||||||
if (errno || metric_int < 0 || metric_int > G_MAXUINT32) {
|
|
||||||
g_match_info_free (match_info);
|
g_match_info_free (match_info);
|
||||||
g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION,
|
g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION,
|
||||||
"Invalid IP6 route metric '%s'", metric);
|
"Invalid IP6 route metric '%s'", metric);
|
||||||
@@ -3489,17 +3484,16 @@ make_wireless_setting (shvarFile *ifcfg,
|
|||||||
|
|
||||||
value = svGetValue (ifcfg, "MTU", FALSE);
|
value = svGetValue (ifcfg, "MTU", FALSE);
|
||||||
if (value) {
|
if (value) {
|
||||||
long int mtu;
|
int mtu;
|
||||||
|
|
||||||
errno = 0;
|
mtu = _nm_utils_ascii_str_to_int64 (value, 10, 0, 50000, -1);
|
||||||
mtu = strtol (value, NULL, 10);
|
if (mtu == -1) {
|
||||||
if (errno || mtu < 0 || mtu > 50000) {
|
|
||||||
g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION,
|
g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION,
|
||||||
"Invalid wireless MTU '%s'", value);
|
"Invalid wireless MTU '%s'", value);
|
||||||
g_free (value);
|
g_free (value);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
g_object_set (s_wireless, NM_SETTING_WIRELESS_MTU, (guint32) mtu, NULL);
|
g_object_set (s_wireless, NM_SETTING_WIRELESS_MTU, (guint) mtu, NULL);
|
||||||
g_free (value);
|
g_free (value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3944,9 +3938,9 @@ parse_infiniband_p_key (shvarFile *ifcfg,
|
|||||||
char **out_parent,
|
char **out_parent,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
char *device = NULL, *physdev = NULL, *pkey_id = NULL, *end;
|
char *device = NULL, *physdev = NULL, *pkey_id = NULL;
|
||||||
char *ifname = NULL;
|
char *ifname = NULL;
|
||||||
guint32 id = G_MAXUINT32;
|
int id;
|
||||||
gboolean ret = FALSE;
|
gboolean ret = FALSE;
|
||||||
|
|
||||||
device = svGetValue (ifcfg, "DEVICE", FALSE);
|
device = svGetValue (ifcfg, "DEVICE", FALSE);
|
||||||
@@ -3967,19 +3961,14 @@ parse_infiniband_p_key (shvarFile *ifcfg,
|
|||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (g_str_has_prefix (pkey_id, "0x"))
|
id = _nm_utils_ascii_str_to_int64 (pkey_id, 0, 0, 0xFFFF, -1);
|
||||||
id = strtoul (pkey_id, &end, 16);
|
if (id == -1) {
|
||||||
else if (!g_str_has_prefix (pkey_id, "0"))
|
|
||||||
id = strtoul (pkey_id, &end, 10);
|
|
||||||
else
|
|
||||||
end = pkey_id;
|
|
||||||
if (end == pkey_id || *end || id > 0xFFFF) {
|
|
||||||
PARSE_WARNING ("invalid InfiniBand PKEY_ID '%s'", pkey_id);
|
PARSE_WARNING ("invalid InfiniBand PKEY_ID '%s'", pkey_id);
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
id = (id | 0x8000);
|
id = (id | 0x8000);
|
||||||
|
|
||||||
ifname = g_strdup_printf ("%s.%04x", physdev, id);
|
ifname = g_strdup_printf ("%s.%04x", physdev, (unsigned) id);
|
||||||
if (strcmp (device, ifname) != 0) {
|
if (strcmp (device, ifname) != 0) {
|
||||||
PARSE_WARNING ("InfiniBand DEVICE (%s) does not match PHYSDEV+PKEY_ID (%s)",
|
PARSE_WARNING ("InfiniBand DEVICE (%s) does not match PHYSDEV+PKEY_ID (%s)",
|
||||||
device, ifname);
|
device, ifname);
|
||||||
@@ -4646,16 +4635,14 @@ make_vlan_setting (shvarFile *ifcfg,
|
|||||||
char *iface_name = NULL;
|
char *iface_name = NULL;
|
||||||
char *parent = NULL;
|
char *parent = NULL;
|
||||||
const char *p = NULL;
|
const char *p = NULL;
|
||||||
char *end = NULL;
|
int vlan_id = -1;
|
||||||
gint vlan_id = -1;
|
|
||||||
guint32 vlan_flags = 0;
|
guint32 vlan_flags = 0;
|
||||||
gint gvrp, reorder_hdr;
|
gint gvrp, reorder_hdr;
|
||||||
|
|
||||||
value = svGetValue (ifcfg, "VLAN_ID", FALSE);
|
value = svGetValue (ifcfg, "VLAN_ID", FALSE);
|
||||||
if (value) {
|
if (value) {
|
||||||
errno = 0;
|
vlan_id = _nm_utils_ascii_str_to_int64 (value, 10, 0, 4096, -1);
|
||||||
vlan_id = (gint) g_ascii_strtoll (value, NULL, 10);
|
if (vlan_id == -1) {
|
||||||
if (vlan_id < 0 || vlan_id > 4096 || errno) {
|
|
||||||
g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION,
|
g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION,
|
||||||
"Invalid VLAN_ID '%s'", value);
|
"Invalid VLAN_ID '%s'", value);
|
||||||
g_free (value);
|
g_free (value);
|
||||||
@@ -4699,12 +4686,13 @@ make_vlan_setting (shvarFile *ifcfg,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (p) {
|
if (p) {
|
||||||
|
int device_vlan_id;
|
||||||
|
|
||||||
/* Grab VLAN ID from interface name; this takes precedence over the
|
/* Grab VLAN ID from interface name; this takes precedence over the
|
||||||
* separate VLAN_ID property for backwards compat.
|
* separate VLAN_ID property for backwards compat.
|
||||||
*/
|
*/
|
||||||
|
device_vlan_id = _nm_utils_ascii_str_to_int64 (p, 10, 0, 4095, -1);
|
||||||
gint device_vlan_id = (gint) g_ascii_strtoll (p, &end, 10);
|
if (device_vlan_id != -1)
|
||||||
if (device_vlan_id >= 0 && device_vlan_id <= 4095 && end != p && !*end)
|
|
||||||
vlan_id = device_vlan_id;
|
vlan_id = device_vlan_id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user