diff options
author | sam <sam@FreeBSD.org> | 2007-02-27 17:11:18 +0000 |
---|---|---|
committer | sam <sam@FreeBSD.org> | 2007-02-27 17:11:18 +0000 |
commit | a0324781f288a9ee994f0fc87aa2adb515d8d393 (patch) | |
tree | 24887f984abbb81e025c5938f621ee19b9d7effd | |
parent | 88a4a229c2a089bbd73c39097be1d75724c89b0f (diff) | |
download | FreeBSD-src-a0324781f288a9ee994f0fc87aa2adb515d8d393.zip FreeBSD-src-a0324781f288a9ee994f0fc87aa2adb515d8d393.tar.gz |
o consistently check strlcpy result
o warn when we skip an interface because it's name is too long
-rw-r--r-- | sbin/ifconfig/ifconfig.c | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/sbin/ifconfig/ifconfig.c b/sbin/ifconfig/ifconfig.c index daa31f3..e03a54d 100644 --- a/sbin/ifconfig/ifconfig.c +++ b/sbin/ifconfig/ifconfig.c @@ -148,6 +148,7 @@ main(int argc, char *argv[]) char options[1024], *cp; const char *ifname; struct option *p; + size_t iflen; all = downonly = uponly = namesonly = verbose = 0; @@ -239,7 +240,10 @@ main(int argc, char *argv[]) */ if (argc > 0 && (strcmp(argv[0], "create") == 0 || strcmp(argv[0], "plumb") == 0)) { - (void) strlcpy(name, ifname, sizeof(name)); + iflen = strlcpy(name, ifname, sizeof(name)); + if (iflen >= sizeof(name)) + errx(1, "%s: cloning name too long", + ifname); ifconfig(argc, argv, NULL); exit(0); } @@ -274,8 +278,12 @@ main(int argc, char *argv[]) sdl = NULL; if (cp != NULL && strcmp(cp, ifa->ifa_name) == 0) continue; - if (strlcpy(name, ifa->ifa_name, sizeof(name)) >= sizeof(name)) + iflen = strlcpy(name, ifa->ifa_name, sizeof(name)); + if (iflen >= sizeof(name)) { + warnx("%s: interface name too long, skipping", + ifa->ifa_name); continue; + } cp = ifa->ifa_name; if (downonly && (ifa->ifa_flags & IFF_UP) != 0) |