From aa302129ad6cdc6fdea4a895cc06c770577efab1 Mon Sep 17 00:00:00 2001 From: ae Date: Sun, 18 Nov 2018 00:26:09 +0000 Subject: [PATCH] MFC r339535: Do not allow use `create` keyword as hostname when ifconfig(8) is invoked for already existing interface. It appeared, that ifconfig(8) assumes `create` keyword as hostname and tries to resolve it, when `ifconfig ifname create` invoked for already existing interface. This can produce some unexpected results, when hostname resolving has successfully happened. This patch adds check for such case. When an interface is already exists, and create is only one argument, return error message. But when there are some other arguments, just remove create keyword from the arguments list. Obtained from: Yandex LLC Sponsored by: Yandex LLC Differential Revision: https://reviews.freebsd.org/D17171 MFC r339536: Fix grammar. --- sbin/ifconfig/ifconfig.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/sbin/ifconfig/ifconfig.c b/sbin/ifconfig/ifconfig.c index 88b2f78577b..958c7aa916f 100644 --- a/sbin/ifconfig/ifconfig.c +++ b/sbin/ifconfig/ifconfig.c @@ -501,6 +501,18 @@ main(int argc, char *argv[]) } #endif errx(1, "interface %s does not exist", ifname); + } else { + /* + * Do not allow use `create` command as hostname if + * address family is not specified. + */ + if (argc > 0 && (strcmp(argv[0], "create") == 0 || + strcmp(argv[0], "plumb") == 0)) { + if (argc == 1) + errx(1, "interface %s already exists", + ifname); + argc--, argv++; + } } } -- 2.45.0