mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager
synced 2024-07-23 03:04:18 +00:00
cli: fix parsing of route metric on 32-bit archs
On 32-bit architectures long and int have the same size and thus it's wrong to use nmc_string_to_int() since it uses strtol() and the @max argument can't represent G_MAXUINT32. Use nmc_string_to_uint() instead. https://bugzilla.redhat.com/show_bug.cgi?id=1350201
This commit is contained in:
parent
c5c9f0aad7
commit
938a4b35c6
|
@ -415,10 +415,12 @@ nmc_parse_and_build_route (int family,
|
|||
char *dest = NULL, *plen = NULL;
|
||||
const char *next_hop = NULL;
|
||||
const char *canon_dest;
|
||||
long int prefix = max_prefix, metric = -1;
|
||||
long int prefix = max_prefix;
|
||||
unsigned long int tmp_ulong;
|
||||
NMIPRoute *route = NULL;
|
||||
gboolean success = FALSE;
|
||||
GError *local = NULL;
|
||||
gint64 metric = -1;
|
||||
|
||||
g_return_val_if_fail (family == AF_INET || family == AF_INET6, FALSE);
|
||||
g_return_val_if_fail (first != NULL, FALSE);
|
||||
|
@ -444,19 +446,21 @@ nmc_parse_and_build_route (int family,
|
|||
next_hop = second;
|
||||
else {
|
||||
/* 'second' can be a metric */
|
||||
if (!nmc_string_to_int (second, TRUE, 0, G_MAXUINT32, &metric)) {
|
||||
if (!nmc_string_to_uint (second, TRUE, 0, G_MAXUINT32, &tmp_ulong)) {
|
||||
g_set_error (error, 1, 0, _("the second component of route ('%s') is neither "
|
||||
"a next hop address nor a metric"), second);
|
||||
goto finish;
|
||||
}
|
||||
metric = tmp_ulong;
|
||||
}
|
||||
}
|
||||
|
||||
if (third) {
|
||||
if (!nmc_string_to_int (third, TRUE, 0, G_MAXUINT32, &metric)) {
|
||||
if (!nmc_string_to_uint (third, TRUE, 0, G_MAXUINT32, &tmp_ulong)) {
|
||||
g_set_error (error, 1, 0, _("invalid metric '%s'"), third);
|
||||
goto finish;
|
||||
}
|
||||
metric = tmp_ulong;
|
||||
}
|
||||
|
||||
route = nm_ip_route_new (family, dest, prefix, next_hop, metric, &local);
|
||||
|
|
Loading…
Reference in a new issue