From patchwork Sun Nov 4 10:43:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Hans-Christian Noren Egtvedt X-Patchwork-Id: 10666835 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CCA891591 for ; Sun, 4 Nov 2018 11:10:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B35E529A1F for ; Sun, 4 Nov 2018 11:10:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A10A829A6E; Sun, 4 Nov 2018 11:10:22 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham 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 3B80D29A1F for ; Sun, 4 Nov 2018 11:10:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729301AbeKDUYz (ORCPT ); Sun, 4 Nov 2018 15:24:55 -0500 Received: from vuizook.err.no ([178.255.151.162]:55012 "EHLO vuizook.err.no" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728868AbeKDUYz (ORCPT ); Sun, 4 Nov 2018 15:24:55 -0500 X-Greylist: delayed 1578 seconds by postgrey-1.27 at vger.kernel.org; Sun, 04 Nov 2018 15:24:54 EST Received: from tix.egtvedt.no ([178.255.151.173]) by vuizook.err.no with esmtp (Exim 4.89) (envelope-from ) id 1gJFsw-0002aD-Ka; Sun, 04 Nov 2018 10:44:03 +0000 From: Hans-Christian Noren Egtvedt To: linux-mmc@vger.kernel.org Cc: Hans-Christian Noren Egtvedt Subject: [PATCH] mmc: use memmove to avoid strncpy on overlapping strings Date: Sun, 4 Nov 2018 11:43:56 +0100 Message-Id: <20181104104356.18120-1-egtvedt@samfundet.no> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Using GCC 8.2.0 I see the following error. /usr/bin/gcc-8 -Wall -Werror -Wuninitialized -Wundef -D_FILE_OFFSET_BITS=64 -D_FORTIFY_SOURCE=2 -g -O2 -Wp,-MMD,./.lsmmc.o.d,-MT,lsmmc.o -c lsmmc.c -o lsmmc.o In file included from /usr/include/string.h:494, from lsmmc.c:46: In function ‘strncpy’, inlined from ‘read_file’ at lsmmc.c:356:3: /usr/include/x86_64-linux-gnu/bits/string_fortified.h:106:10: error: ‘__builtin_strncpy’ accessing 4096 bytes at offsets 0 and 1 overlaps 4095 bytes at offset 1 [-Werror=restrict] return __builtin___strncpy_chk (__dest, __src, __len, __bos (__dest)); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ cc1: all warnings being treated as errors Makefile:36: recipe for target 'lsmmc.o' failed make: *** [lsmmc.o] Error 1 Hence replace the strncpy with memmove, since using strncpy on overlapping strings is not allowed. Signed-off-by: Hans-Christian Noren Egtvedt --- lsmmc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lsmmc.c b/lsmmc.c index c4faa00..7637198 100644 --- a/lsmmc.c +++ b/lsmmc.c @@ -353,7 +353,7 @@ char *read_file(char *name) line[strlen(line) - 1] = '\0'; while (isspace(line[0])) - strncpy(&line[0], &line[1], sizeof(line)); + memmove(&line[0], &line[1], sizeof(line) - 1); return strdup(line); }