]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
Prevent renaming interfaces to empty string.
authorPatrick McHardy <kaber@trash.net>
Fri, 12 Oct 2007 12:01:13 +0000 (14:01 +0200)
committerStephen Hemminger <shemminger@linux-foundation.org>
Fri, 12 Oct 2007 22:45:12 +0000 (15:45 -0700)
Andreas Henriksson wrote:
> From: Alexander Wirt <formorer@debian.org>
>
>
> Signed-off-by: Andreas Henriksson <andreas@fatal.se>
> ---
>  ip/iplink.c |    4 ++++
>  1 files changed, 4 insertions(+), 0 deletions(-)
>
> diff --git a/ip/iplink.c b/ip/iplink.c
> index 4060845..da1f64e 100644
> --- a/ip/iplink.c
> +++ b/ip/iplink.c
> @@ -670,6 +670,10 @@ static int do_set(int argc, char **argv)
>   }
>
>   if (newname && strcmp(dev, newname)) {
> + if (strlen(newname) == 0) {
> +     printf("\"\" is not valid device identifier\n");
> +     return -1;
> + }

Indentation fixed, same change for the non-ioctl case, use invarg.
While I'm at it I also fixed the error message for "name too long",
*argv is NULL at this point.

Signed-off-by: Patrick McHardy <kaber@trash.net>
ip/iplink.c

index 4060845cc8b78596504b68d33c87c7466396c504..8e0ed2ab9e3ae0fac20e957686de66b3f1bcfead 100644 (file)
@@ -336,8 +336,10 @@ static int iplink_modify(int cmd, unsigned int flags, int argc, char **argv)
 
        if (name) {
                len = strlen(name) + 1;
+               if (len == 1)
+                       invarg("\"\" is not a valid device identifier\n", "name");
                if (len > IFNAMSIZ)
-                       invarg("\"name\" too long\n", *argv);
+                       invarg("\"name\" too long\n", name);
                addattr_l(&req.n, sizeof(req), IFLA_IFNAME, name, len);
        }
 
@@ -670,6 +672,8 @@ static int do_set(int argc, char **argv)
        }
 
        if (newname && strcmp(dev, newname)) {
+               if (strlen(newname) == 0)
+                       invarg("\"\" is not a valid device identifier\n", "name");
                if (do_changename(dev, newname) < 0)
                        return -1;
                dev = newname;