daandemeyer / rpms / systemd

Forked from rpms/systemd 2 years ago
Clone
1ff636
From f50fbeaf7c2ce57027f774d02d9e2b09f810ec2a Mon Sep 17 00:00:00 2001
1ff636
From: Tom Gundersen <teg@jklm.no>
1ff636
Date: Thu, 21 May 2015 15:22:07 +0200
1ff636
Subject: [PATCH] udev: link-config - fix corruption
1ff636
1ff636
The parser used for MTU and Speed expects them to be size_t, not unsigned int.
1ff636
1ff636
This caused a corruption in the rest of the structure.
1ff636
1ff636
Reported by David O Neill <david.m.oneill@intel.com>.
1ff636
1ff636
(cherry picked from commit dab495dc23bf9a5ba0487a057bb594355555a0e9)
1ff636
1ff636
Cherry-picked from: dab495d
1ff636
Resolves: #1222517
1ff636
---
1ff636
 src/udev/net/link-config.c | 11 ++++++-----
1ff636
 src/udev/net/link-config.h |  4 ++--
1ff636
 2 files changed, 8 insertions(+), 7 deletions(-)
1ff636
1ff636
diff --git a/src/udev/net/link-config.c b/src/udev/net/link-config.c
c62b8e
index 8b3dc45d4e..489593f4fd 100644
1ff636
--- a/src/udev/net/link-config.c
1ff636
+++ b/src/udev/net/link-config.c
1ff636
@@ -177,6 +177,9 @@ static int load_link(link_config_ctx *ctx, const char *filename) {
1ff636
         else
1ff636
                 log_debug("Parsed configuration file %s", filename);
1ff636
 
1ff636
+        if (link->mtu > UINT_MAX || link->speed > UINT_MAX)
1ff636
+                return -ERANGE;
1ff636
+
1ff636
         link->filename = strdup(filename);
1ff636
 
1ff636
         LIST_PREPEND(links, ctx->links, link);
1ff636
@@ -379,10 +382,9 @@ int link_config_apply(link_config_ctx *ctx, link_config *config,
1ff636
         if (!old_name)
1ff636
                 return -EINVAL;
1ff636
 
1ff636
-        r = ethtool_set_speed(&ctx->ethtool_fd, old_name, config->speed / 1024,
1ff636
-                              config->duplex);
1ff636
+        r = ethtool_set_speed(&ctx->ethtool_fd, old_name, config->speed / 1024, config->duplex);
1ff636
         if (r < 0)
1ff636
-                log_warning_errno(r, "Could not set speed or duplex of %s to %u Mbps (%s): %m",
1ff636
+                log_warning_errno(r, "Could not set speed or duplex of %s to %zu Mbps (%s): %m",
1ff636
                                   old_name, config->speed / 1024,
1ff636
                                   duplex_to_string(config->duplex));
1ff636
 
1ff636
@@ -461,8 +463,7 @@ int link_config_apply(link_config_ctx *ctx, link_config *config,
1ff636
                         mac = config->mac;
1ff636
         }
1ff636
 
1ff636
-        r = rtnl_set_link_properties(&ctx->rtnl, ifindex, config->alias, mac,
1ff636
-                                     config->mtu);
1ff636
+        r = rtnl_set_link_properties(&ctx->rtnl, ifindex, config->alias, mac, config->mtu);
1ff636
         if (r < 0)
1ff636
                 return log_warning_errno(r, "Could not set Alias, MACAddress or MTU on %s: %m", old_name);
1ff636
 
1ff636
diff --git a/src/udev/net/link-config.h b/src/udev/net/link-config.h
c62b8e
index cb434d1aee..f2e9174887 100644
1ff636
--- a/src/udev/net/link-config.h
1ff636
+++ b/src/udev/net/link-config.h
1ff636
@@ -67,8 +67,8 @@ struct link_config {
1ff636
         NamePolicy *name_policy;
1ff636
         char *name;
1ff636
         char *alias;
1ff636
-        unsigned int mtu;
1ff636
-        unsigned int speed;
1ff636
+        size_t mtu;
1ff636
+        size_t speed;
1ff636
         Duplex duplex;
1ff636
         WakeOnLan wol;
1ff636