From patchwork Tue Nov 13 22:55:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 997406 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=chromium.org Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 42vjdf5pZgz9rxp for ; Wed, 14 Nov 2018 09:55:34 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 7DB25C21FEC; Tue, 13 Nov 2018 22:55:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 435F5C21DB6; Tue, 13 Nov 2018 22:55:27 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 5F158C21DB6; Tue, 13 Nov 2018 22:55:26 +0000 (UTC) Received: from mail-it1-f201.google.com (mail-it1-f201.google.com [209.85.166.201]) by lists.denx.de (Postfix) with ESMTPS id D1DC0C21DA6 for ; Tue, 13 Nov 2018 22:55:25 +0000 (UTC) Received: by mail-it1-f201.google.com with SMTP id o205so4946710itc.2 for ; Tue, 13 Nov 2018 14:55:25 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=EhuNFublDfKVMjH2i4d+ewjay633kZKAXfLxz4uMF5M=; b=h2LQz2UayD5bE43HJM/GlMWPxM0B4uIxlfEHayuZcDyvxdaVRoB3JBi8EnfRjoNw3N KnQswkUUnUuWeAx7qEbAZQY49jQr7xrVk99Alcz1trm3kfVsFGZMOpSag3pwq1BX4q6C HI8j0GdeULT+DCUhwlHdyTQVNQK25fKgcT3fzPwCPSSDjhxnccQkVF/YQGagHzpzvB7v TdWUbHQyW9fK+FooelPon8J9Zr8DdjXNjCsbcykUf5Om5fT/3ZYgjviNWvkXpZGrPtch H+haqQhTqumQxjiZ6jlHxRAXJ/RaDPYxGkCemZgD7seQ8qftrfHIKa4NI11QLJO2qawZ 0vMw== X-Gm-Message-State: AGRZ1gJ+gnLJ1gPNKOBLHRhM/kXYOojxgIXiIqHbQ+sUkWc9px3GZZuC G/da3Iq5eBYHZPX1jTZ+KaMpnJs= X-Google-Smtp-Source: AJdET5eNwucVf/vnBpnvFt4HCoo2qMENkzm/2jIJl/MefpQn5tbzWGdlgI5+swog+pXPZptkF8htCiM= X-Received: by 2002:a24:3342:: with SMTP id k63-v6mr4544787itk.3.1542149724753; Tue, 13 Nov 2018 14:55:24 -0800 (PST) Date: Tue, 13 Nov 2018 15:55:20 -0700 Message-Id: <20181113225521.49103-1-sjg@chromium.org> Mime-Version: 1.0 X-Mailer: git-send-email 2.19.1.930.g4563a0d9d0-goog From: Simon Glass To: U-Boot Mailing List Cc: Tom Rini , Alexander Graf Subject: [U-Boot] [PATCH v3] sandbox: Use memmove() to move overlapping regions X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" The use of strcpy() to remove characters at the start of a string is safe in U-Boot, since we know the implementation. But in os.c we are using the C library's strcpy() function, where this behaviour is not permitted. Update the code to use memmove() instead. Reported-by: Coverity (CID: 173279) Signed-off-by: Simon Glass Reviewed-by: Alexander Graf Reviewed-by: Alexander Graf --- Changes in v3: - Fix commit message to say memmove() instead of memcpy() Changes in v2: - Also remove the leading / from the "/spl" path - Correct the string calculation arch/sandbox/cpu/os.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/arch/sandbox/cpu/os.c b/arch/sandbox/cpu/os.c index 07e46471fe5..04669bfc177 100644 --- a/arch/sandbox/cpu/os.c +++ b/arch/sandbox/cpu/os.c @@ -641,9 +641,10 @@ int os_find_u_boot(char *fname, int maxlen) } /* Look for 'u-boot' in the parent directory of spl/ */ - p = strstr(fname, "/spl/"); + p = strstr(fname, "spl/"); if (p) { - strcpy(p, p + 4); + /* Remove the "spl" characters */ + memmove(p, p + 4, strlen(p + 4) + 1); fd = os_open(fname, O_RDONLY); if (fd >= 0) { close(fd);