From patchwork Thu Mar 29 08:19:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Khem Raj X-Patchwork-Id: 10314723 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 C181260353 for ; Thu, 29 Mar 2018 08:19:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A9CEB22A65 for ; Thu, 29 Mar 2018 08:19:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9C6B92A202; Thu, 29 Mar 2018 08:19:34 +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=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID 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 0E4C42A1FC for ; Thu, 29 Mar 2018 08:19:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750753AbeC2ITb (ORCPT ); Thu, 29 Mar 2018 04:19:31 -0400 Received: from mail-pg0-f65.google.com ([74.125.83.65]:33178 "EHLO mail-pg0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750716AbeC2ITb (ORCPT ); Thu, 29 Mar 2018 04:19:31 -0400 Received: by mail-pg0-f65.google.com with SMTP id i194so2606109pgd.0 for ; Thu, 29 Mar 2018 01:19:31 -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; bh=aDD82o2az5TjGbDdH7TsO0ptXkhpG9qZNcMLfnbEl5A=; b=H4Ea9L/FzGRdGgutdtnQMSMGh6xci6EwwCySXXm1j6ekJj7PNvsvoYWXdjP99CxNl1 XEeBxI4jGgymIFycNhPP48WugL9lv00lK0Cknb1nkFjNRLrVZzncF/Med0ryZdqLRJtH HmqNwFOWLuB7JgVZZhFTz8T2GqAJom8Cob+pOULaRUOwdHYwnle2VVRAcl1MrS0gnGny xbU/2qJsRAf2ekctRkHQGRmHRv6zcBthZlRoe3CXhf7dipLK30hr5J4fSeEc5TA8w7cX J/MBXnZXe+oWupOLKGqkQhoiLV/TtgZWESPZo+55EFxpSJh7BPOLBIcdgoE7Xr317geA MYew== 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; bh=aDD82o2az5TjGbDdH7TsO0ptXkhpG9qZNcMLfnbEl5A=; b=RiQdgPfcLSODIHkiS9R/B0fbpvEDhpX5dhC1NPGq/BBsVW+PO4ua+kyx2SLaXkgsea ybrPvj0RquJ7E0e/FK5l+SZY3sinUfXu3iNKoxf/iBMYc6zHFLdR4fvjRgtkcH2fcDbt AyS3BGRhbdrjUMt/FaIbYr9Es9OQIT3obnpuvq6ayYgXdbjOzEvsfYOKXmfiCTrFW6O3 tye6U5T9HRsPOhSNtdb/aeJeodVeG/A3M8A7xPSgZXnY3xsCRkNoKsVUy9s9zadQ8Z+R vvHO2v7zfx6d5DzOSTkMkr+vcnqM3nwDMTGXkFDYDzigTdh2T2Kk/Xajmyj5ZeKaKXZi de3Q== X-Gm-Message-State: AElRT7FkVz22wqmwt26z/veOxVBSpRO1ZpkoAJCQBVmrIROhwFsGUjKi vxdKq0UxesUDi3aW1P9Prh+5gA== X-Google-Smtp-Source: AIpwx49JkvOyYiyapBc+3ZKR1/bISctk6R0wGcbbrzdfxzXogI5Ojf9j53gOw8V2xnnuDG95SxizWQ== X-Received: by 10.101.86.198 with SMTP id w6mr4846656pgs.294.1522311570597; Thu, 29 Mar 2018 01:19:30 -0700 (PDT) Received: from localhost.localdomain ([2601:646:8880:466c:6245:cbff:fe64:591]) by smtp.gmail.com with ESMTPSA id n22sm11276056pff.19.2018.03.29.01.19.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 29 Mar 2018 01:19:29 -0700 (PDT) From: Khem Raj To: linux-mmc@vger.kernel.org Cc: Khem Raj Subject: [PATCH] lsmmc: replace strncpy with memmove on overlapping memory copy Date: Thu, 29 Mar 2018 01:19:14 -0700 Message-Id: <20180329081914.43509-1-raj.khem@gmail.com> X-Mailer: git-send-email 2.16.3 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 here source and destination addresses are overlapping so using memmove is going to be more efficient. Additionally, the bounded size for copy is overflowing for first copy In function 'strncpy', inlined from 'read_file' at lsmmc.c:356:3: /mnt/a/oe/build/tmp/work/cortexa7t2hf-neon-vfpv4-bec-linux-gnueabi/mmc-utils/0.1-r0/recipe-sysroot/usr/include/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)); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Signed-off-by: Khem Raj --- lsmmc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) -- To unsubscribe from this list: send the line "unsubscribe linux-mmc" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/lsmmc.c b/lsmmc.c index c4faa00..bcb854d 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); }