From mboxrd@z Thu Jan 1 00:00:00 1970 From: Patrick Talbert Subject: [PATCH iproute2] ipaddress: strengthen check on 'label' input Date: Tue, 24 Apr 2018 16:08:21 +0200 Message-ID: <1524578901-28278-1-git-send-email-ptalbert@redhat.com> Cc: stephen@networkplumber.org To: netdev@vger.kernel.org Return-path: Received: from mx3-rdu2.redhat.com ([66.187.233.73]:47702 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752630AbeDXOI1 (ORCPT ); Tue, 24 Apr 2018 10:08:27 -0400 Sender: netdev-owner@vger.kernel.org List-ID: As mentioned in the ip-address man page, an address label must be equal to the device name or prefixed by the device name followed by a colon. Currently the only check on this input is to see if the device name appears at the beginning of the label string. This commit adds an additional check to ensure label == dev or continues with a colon. Signed-off-by: Patrick Talbert --- ip/ipaddress.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/ip/ipaddress.c b/ip/ipaddress.c index aecc9a1..edcf821 100644 --- a/ip/ipaddress.c +++ b/ip/ipaddress.c @@ -2168,9 +2168,14 @@ static int ipaddr_modify(int cmd, int flags, int argc, char **argv) fprintf(stderr, "Not enough information: \"dev\" argument is required.\n"); return -1; } - if (l && matches(d, l) != 0) { - fprintf(stderr, "\"dev\" (%s) must match \"label\" (%s).\n", d, l); - return -1; + if (l) { + size_t d_len = strlen(d); + + if (!(matches(d, l) == 0 && (l[d_len] == '\0' || l[d_len] == ':'))) { + fprintf(stderr, "\"label\" (%s) must match \"dev\" (%s) or be prefixed by" + " \"dev\" with a colon.\n", l, d); + return -1; + } } if (peer_len == 0 && local_len) { -- 1.8.3.1