From patchwork Wed Feb 4 09:52:09 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Neelesh Gupta X-Patchwork-Id: 436212 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [103.22.144.68]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 941D3140190 for ; Wed, 4 Feb 2015 20:55:12 +1100 (AEDT) Received: from ozlabs.org (ozlabs.org [103.22.144.67]) by lists.ozlabs.org (Postfix) with ESMTP id 4C8071A09F9 for ; Wed, 4 Feb 2015 20:55:12 +1100 (AEDT) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Received: from e23smtp05.au.ibm.com (e23smtp05.au.ibm.com [202.81.31.147]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 1B4591A09D7 for ; Wed, 4 Feb 2015 20:55:09 +1100 (AEDT) Received: from /spool/local by e23smtp05.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 4 Feb 2015 19:55:07 +1000 Received: from d23dlp03.au.ibm.com (202.81.31.214) by e23smtp05.au.ibm.com (202.81.31.211) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 4 Feb 2015 19:55:05 +1000 Received: from d23relay06.au.ibm.com (d23relay06.au.ibm.com [9.185.63.219]) by d23dlp03.au.ibm.com (Postfix) with ESMTP id 8EFC5357804C for ; Wed, 4 Feb 2015 20:55:05 +1100 (EST) Received: from d23av04.au.ibm.com (d23av04.au.ibm.com [9.190.235.139]) by d23relay06.au.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id t149suOO19136706 for ; Wed, 4 Feb 2015 20:55:05 +1100 Received: from d23av04.au.ibm.com (localhost [127.0.0.1]) by d23av04.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id t149sUXf013400 for ; Wed, 4 Feb 2015 20:54:31 +1100 Received: from localhost.localdomain ([9.124.35.239]) by d23av04.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id t149sTpr013070 for ; Wed, 4 Feb 2015 20:54:30 +1100 To: skiboot@lists.ozlabs.org From: Neelesh Gupta Date: Wed, 04 Feb 2015 15:22:09 +0530 Message-ID: <20150204095205.27285.46222.stgit@localhost.localdomain> In-Reply-To: <20150204095135.27285.71713.stgit@localhost.localdomain> References: <20150204095135.27285.71713.stgit@localhost.localdomain> User-Agent: StGit/0.16 MIME-Version: 1.0 X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 15020409-0017-0000-0000-000000C26F27 Subject: [Skiboot] [PATCH 2/2] libc/memmove: Correct the buffer overlap condition X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" Signed-off-by: Neelesh Gupta --- libc/string/memmove.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/libc/string/memmove.c b/libc/string/memmove.c index 3acf1a9..844f300 100644 --- a/libc/string/memmove.c +++ b/libc/string/memmove.c @@ -21,15 +21,14 @@ memmove(void *dest, const void *src, size_t n) int i; /* Do the buffers overlap in a bad way? */ - if (src < dest && src + n >= dest) { + if (src < dest && src + n - 1 >= dest) { /* Copy from end to start */ cdest = dest + n - 1; csrc = src + n - 1; for (i = 0; i < n; i++) { *cdest-- = *csrc--; } - } - else { + } else { /* Normal copy is possible */ cdest = dest; csrc = src;