From patchwork Mon Jun 25 12:45:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stafford Horne X-Patchwork-Id: 10485923 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id DC76E60230 for ; Mon, 25 Jun 2018 12:46:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C829B286C1 for ; Mon, 25 Jun 2018 12:46:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BCC8628727; Mon, 25 Jun 2018 12:46:33 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 25DF2286C1 for ; Mon, 25 Jun 2018 12:46:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755439AbeFYMqH (ORCPT ); Mon, 25 Jun 2018 08:46:07 -0400 Received: from mail-pf0-f195.google.com ([209.85.192.195]:43426 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755429AbeFYMqD (ORCPT ); Mon, 25 Jun 2018 08:46:03 -0400 Received: by mail-pf0-f195.google.com with SMTP id y8-v6so6392642pfm.10; Mon, 25 Jun 2018 05:46:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/fFwUTOq5TotVWM5uJztPWAemINo6V3+BKTxyGrVtys=; b=IMpcRKlnjG7lvrzYdDM4q4OOv3KhbIL6JSwjmN+JLjg8Y2z6CtRwOxoOEwpxqRrmAH +XWdsLkiaP+3ggwzN+ISeTPxWrW3rvxVm1cEeJ4JecfDszXEqdgmnm/9iVMyHngwYNbw XP8as88TmNyHsQdA/2Jl2b6AIdXGbvy39qJ85Z5bZjCgAGmqBSvgVq3n7byaNvWgfZjg YPMInfJP3wvzO3IYXBLW7ekkxkqvUkIJ0/ZcVlVlRsSzZdmuIqSST4rdJq+9h0G9k+Xr l6o2iZOVViIPmj3hKhOz/MaQRXb/AhOfRbgqQXN1Ucj95jx42vtZvWkUOk1xMyxIeYYh wKKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/fFwUTOq5TotVWM5uJztPWAemINo6V3+BKTxyGrVtys=; b=A10Y4f9FQ84YZZUFJAM/v4aer/lxAT30pv8x3jwzJE2+EpAdtA2SHPOH2fdRjG+uo/ 1/BOWiGb8Ss/XN5KVmIaGL8pmUDZz7Sd5oj6J9xtoFDX2tzV4wk/okljIt6hXGlJuJB7 Ap6EmusqjpSEDpd9H9Kv98eVEzc817y31ZjHaqPKTpXI282q0BGYMlVbY7S7OO3sIxFx bH5PCA6K1tfAYS4wn42hN16IDjyYsyzSiCs2hj51ZSh8UVRHZS++6b/xlaq94lfYjqMi L8yXEa6A5YN4Tybn9GecQKN3lmrepXD0UF98/YoBga88NYZkpg6IQ0rDU+DKayZSp8B1 aEgw== X-Gm-Message-State: APt69E3FYDWvtx8fBoeTvMaH0k9tc5SNNTUxeK9QzSuVJUA/OSSYxLll pHTYGAcBzA65t3vr/MyamusSvWe/cco= X-Google-Smtp-Source: ADUXVKI28s8I+EaQ9BRiDQYdJf8pp6vRz5PQ0jXv/zOyoE/sMlX7IIjq/owFwJop2hmfZzZg5Zpuig== X-Received: by 2002:a63:80c3:: with SMTP id j186-v6mr10778181pgd.426.1529930762928; Mon, 25 Jun 2018 05:46:02 -0700 (PDT) Received: from localhost (g134.124-44-9.ppp.wakwak.ne.jp. [124.44.9.134]) by smtp.gmail.com with ESMTPSA id y4-v6sm3479214pgy.18.2018.06.25.05.46.01 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 25 Jun 2018 05:46:02 -0700 (PDT) From: Stafford Horne To: LKML Cc: Greg KH , arnd@arndb.de, Eric Biggers , linux-crypto@vger.kernel.org, Stafford Horne Subject: [PATCH v2 2/2] kobject: Fix -Wstringop-truncation warning Date: Mon, 25 Jun 2018 21:45:38 +0900 Message-Id: <20180625124538.21051-3-shorne@gmail.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180625124538.21051-1-shorne@gmail.com> References: <20180625124538.21051-1-shorne@gmail.com> MIME-Version: 1.0 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When compiling with GCC 9.0.0 I am seeing the following warning: In function ‘fill_kobj_path’, inlined from ‘kobject_get_path’ at lib/kobject.c:155:2: lib/kobject.c:128:3: warning: ‘strncpy’ output truncated before terminating nul copying as many bytes from a string as its length [-Wstringop-truncation] strncpy(path + length, kobject_name(parent), cur); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ lib/kobject.c: In function ‘kobject_get_path’: lib/kobject.c:125:13: note: length computed here int cur = strlen(kobject_name(parent)); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~ This is not really an issue since the buffer we are writing to is pre-zero'd and we have already allocated the buffer based on the calculated strlen size and accounted for the terminating '\0'. Just use memcpy() instead. Cc: Greg Kroah-Hartman Cc: Arnd Bergmann Cc: Eric Biggers Signed-off-by: Stafford Horne Reviewed-by: Christophe Leroy --- lib/kobject.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/kobject.c b/lib/kobject.c index 18989b5b3b56..e876957743c8 100644 --- a/lib/kobject.c +++ b/lib/kobject.c @@ -125,7 +125,7 @@ static void fill_kobj_path(struct kobject *kobj, char *path, int length) int cur = strlen(kobject_name(parent)); /* back up enough to print this name with '/' */ length -= cur; - strncpy(path + length, kobject_name(parent), cur); + memcpy(path + length, kobject_name(parent), cur); *(path + --length) = '/'; }