From patchwork Thu Apr 5 17:01:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Khem Raj X-Patchwork-Id: 132876 Delivered-To: patch@linaro.org Received: by 10.46.84.29 with SMTP id i29csp6523514ljb; Thu, 5 Apr 2018 10:01:55 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+CWsaWz6jntuFRcPfANOkzNpejZWVgK68n4P2XW+JZFR0kF04JTgJib4/APBGoVzCD+1P0 X-Received: by 2002:a17:902:f64:: with SMTP id 91-v6mr23699238ply.397.1522947715615; Thu, 05 Apr 2018 10:01:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522947715; cv=none; d=google.com; s=arc-20160816; b=ZhgXtze3d9qaNGrascBNA0It0DYWTh2zQNo4lj+qrHa4tg/NlYDibZ4HF7kh/uS4w7 r4ugj6txGxh/uAVl4h7D9J5WWUN6sLv9dSf1H3nIBJo+U4ZCixgQrZC/TOqiXxT0ODJN lzjDoxVg+AE+Y/CCbKRi5783MyxXB+1bDVy7p0oCtZ4x+G2LvyRFzofsMHZLfGW0E3EW 6vvjm0vzq86UYO8ksIJKBxjujK12RhBCkMNJ00GpZGU326ojSO6T9FN5GLn15C8Yuu3G HY1NLbB2AKB8gk2BLI7UWqzuCc4sGsFnnlOJceyeLVPiCvHcdfkH7nUZhd6FuhUcPCPX M6zg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=zypxE1MPezjNQo2lj7NKJgtL/F8I0IBYiYwoikmI/Bw=; b=O9MNejr0niZgTXdGa/PbTLLOp53HhVbyGmM/upqil3e/+Rxuc9InHZTiGVFGQvxlNF t56DLBMSFCaOcZ0QbZqy7OHA2JqdcThihYX7kNsKic9YkpNjzpfqgEE15zaDCptN+Z4v ao6FXHa9i7r6Vxs8ky7J0NGnUhpKhy5YeE4kAYP8MhLZrkCnS4iI97R4BbjyEk4WK9VC 6doq/y4BO9tRiMIJO8f3BnEl+CJAzEWOGN7bkJGEhqUgbM7CKggyanImOIueN4OPX6u/ 3SmHwF2THrffme1MuPfVZIwmZ+aESHOLE4di8056+tEUVTxmfItzUStIN40blCW7wrLG +J1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=r6q23JUv; spf=pass (google.com: best guess record for domain of linux-mmc-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-mmc-owner@vger.kernel.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n10-v6si5951773plk.689.2018.04.05.10.01.55; Thu, 05 Apr 2018 10:01:55 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-mmc-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=r6q23JUv; spf=pass (google.com: best guess record for domain of linux-mmc-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-mmc-owner@vger.kernel.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751368AbeDERBy (ORCPT + 6 others); Thu, 5 Apr 2018 13:01:54 -0400 Received: from mail-pl0-f67.google.com ([209.85.160.67]:45373 "EHLO mail-pl0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751329AbeDERBx (ORCPT ); Thu, 5 Apr 2018 13:01:53 -0400 Received: by mail-pl0-f67.google.com with SMTP id v18-v6so18016391ply.12 for ; Thu, 05 Apr 2018 10:01:53 -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=r6q23JUvPgHfkjM5jJdYpodFZLLTtl5wPNF+NfJpgpaYqcoGRBbArRLShtNr1zPMGx qTRoFW2ivnVrsAnvWXt/S2NWbLT5zCDb1O8aZZ72Cqo0PYGr9hpCvSUZ1NTeIWdMugYP 6uWOVxwTOL7eMUqDfKS/IyL2NC42zBJ/rvwhO8yVehIel/j6DZj3BTUVQnNWfXWEKTmZ XA6Eu3O/PVDEON/nIqUV2Xk1WhmTGBkALQJtJr9zbqWLFKKWT0UXZck4UaIrS06eCnns qQjrQos/8CcGOPoHbvaIg+l4UkpDnkB+X9x1E05RKOMffr+Ky1v2344D4rqnW4sR0Cko AEew== 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=GVfxuuhMIlfdzfqGHDYpgr6lo9CLYiuUXtT129mbl4IbIhDfgO1Z0opfu8b0K3ZAdT 4Xk5+nBWyjvkDoVBZODEirY1bmQoSs+8F49q8eARwVpsmJPBlAGRg+qOVMMIc5vEBEGw Web460AUfwmxphbEiwYIjgPeUI+9yY68KnLaDSbZ6C32+D9RiT2ehlf1yjvY7a6Oh13Z yWFNOpLcSrChcOxI99q0l8mbVjAK+KUnJ1f2gzshjbrIkpHtdkdAqQBiJosmyjz5RzrQ zDw3yYWSBYuTFTva/ku9JiikM3543KOOw1qkYKR2RnHi//XBFi3V6fezrG7WhnKtUSKR GUEg== X-Gm-Message-State: AElRT7Gvc9R8oaluNasC6xO26OA4ks7vg6RreGf0IDO2+Th1EKUEZ+7s zHPj/VNUawlrNVVQ4Jbes8quRg== X-Received: by 2002:a17:902:6984:: with SMTP id l4-v6mr24496918plk.61.1522947713126; Thu, 05 Apr 2018 10:01:53 -0700 (PDT) Received: from localhost.localdomain ([2601:646:8880:466c:6245:cbff:fe64:591]) by smtp.gmail.com with ESMTPSA id e3sm16257673pfb.120.2018.04.05.10.01.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 05 Apr 2018 10:01:52 -0700 (PDT) From: Khem Raj To: linux-mmc@vger.kernel.org, cjb@laptop.org Cc: Khem Raj Subject: [PATCH] lsmmc: replace strncpy with memmove on overlapping memory copy Date: Thu, 5 Apr 2018 10:01:41 -0700 Message-Id: <20180405170141.31075-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 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); }