From patchwork Thu Aug 24 09:51:45 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phil Sutter X-Patchwork-Id: 805403 X-Patchwork-Delegate: shemminger@vyatta.com Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3xdKMV3L14z9sRW for ; Thu, 24 Aug 2017 19:52:06 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752659AbdHXJwE (ORCPT ); Thu, 24 Aug 2017 05:52:04 -0400 Received: from orbyte.nwl.cc ([151.80.46.58]:56427 "EHLO mail.nwl.cc" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752555AbdHXJwD (ORCPT ); Thu, 24 Aug 2017 05:52:03 -0400 Received: from mail.nwl.cc (orbyte.nwl.cc [127.0.0.1]) by mail.nwl.cc (Postfix) with ESMTP id 335B163860; Thu, 24 Aug 2017 11:52:02 +0200 (CEST) Received: from xsao (localhost [IPv6:::1]) by mail.nwl.cc (Postfix) with ESMTP id 0FCE06385D; Thu, 24 Aug 2017 11:52:02 +0200 (CEST) From: Phil Sutter To: Stephen Hemminger Cc: netdev@vger.kernel.org Subject: [iproute PATCH v4 1/6] ipntable: Avoid memory allocation for filter.name Date: Thu, 24 Aug 2017 11:51:45 +0200 Message-Id: <20170824095150.5469-2-phil@nwl.cc> X-Mailer: git-send-email 2.13.1 In-Reply-To: <20170824095150.5469-1-phil@nwl.cc> References: <20170824095150.5469-1-phil@nwl.cc> X-Virus-Scanned: ClamAV using ClamSMTP Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org The original issue was that filter.name might end up unterminated if user provided string was too long. But in fact it is not necessary to copy the commandline parameter at all: just make filter.name point to it instead. Signed-off-by: Phil Sutter --- ip/ipntable.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ip/ipntable.c b/ip/ipntable.c index 1837909fa42e7..88236ce0ec1e1 100644 --- a/ip/ipntable.c +++ b/ip/ipntable.c @@ -37,7 +37,7 @@ static struct int family; int index; #define NONE_DEV (-1) - char name[1024]; + const char *name; } filter; static void usage(void) __attribute__((noreturn)); @@ -367,7 +367,7 @@ static int print_ntable(const struct sockaddr_nl *who, struct nlmsghdr *n, void if (tb[NDTA_NAME]) { const char *name = rta_getattr_str(tb[NDTA_NAME]); - if (strlen(filter.name) > 0 && strcmp(filter.name, name)) + if (filter.name && strcmp(filter.name, name)) return 0; } if (tb[NDTA_PARMS]) { @@ -631,7 +631,7 @@ static int ipntable_show(int argc, char **argv) } else if (strcmp(*argv, "name") == 0) { NEXT_ARG(); - strncpy(filter.name, *argv, sizeof(filter.name)); + filter.name = *argv; } else invarg("unknown", *argv);