From patchwork Thu Aug 24 09:51:48 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phil Sutter X-Patchwork-Id: 805405 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 3xdKMs0sZtz9s1h for ; Thu, 24 Aug 2017 19:52:25 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752697AbdHXJwX (ORCPT ); Thu, 24 Aug 2017 05:52:23 -0400 Received: from orbyte.nwl.cc ([151.80.46.58]:33691 "EHLO mail.nwl.cc" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751317AbdHXJwW (ORCPT ); Thu, 24 Aug 2017 05:52:22 -0400 Received: from mail.nwl.cc (orbyte.nwl.cc [127.0.0.1]) by mail.nwl.cc (Postfix) with ESMTP id 15F9563860; Thu, 24 Aug 2017 11:52:21 +0200 (CEST) Received: from xsao (localhost [IPv6:::1]) by mail.nwl.cc (Postfix) with ESMTP id EC8936385D; Thu, 24 Aug 2017 11:52:20 +0200 (CEST) From: Phil Sutter To: Stephen Hemminger Cc: netdev@vger.kernel.org Subject: [iproute PATCH v4 4/6] lnstat_util: Simplify alloc_and_open() a bit Date: Thu, 24 Aug 2017 11:51:48 +0200 Message-Id: <20170824095150.5469-5-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 Relying upon callers and using unsafe strcpy() is probably not the best idea. Aside from that, using snprintf() allows to format the string for lf->path in one go. Signed-off-by: Phil Sutter --- misc/lnstat_util.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/misc/lnstat_util.c b/misc/lnstat_util.c index cc54598fe1bef..ec19238c24b94 100644 --- a/misc/lnstat_util.c +++ b/misc/lnstat_util.c @@ -180,11 +180,8 @@ static struct lnstat_file *alloc_and_open(const char *path, const char *file) } /* initialize */ - /* de->d_name is guaranteed to be <= NAME_MAX */ - strcpy(lf->basename, file); - strcpy(lf->path, path); - strcat(lf->path, "/"); - strcat(lf->path, lf->basename); + snprintf(lf->basename, sizeof(lf->basename), "%s", file); + snprintf(lf->path, sizeof(lf->path), "%s/%s", path, file); /* initialize to default */ lf->interval.tv_sec = 1;