From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 868 invoked by alias); 8 Mar 2012 14:21:41 -0000 Received: (qmail 802 invoked by uid 22791); 8 Mar 2012 14:21:40 -0000 X-SWARE-Spam-Status: No, hits=-2.0 required=5.0 tests=AWL,BAYES_00,TW_CP,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mail.allinea.com (HELO mail.allinea.com) (94.125.131.200) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 08 Mar 2012 14:21:26 +0000 Received: from localhost (localhost [127.0.0.1]) by mail.allinea.com (Postfix) with ESMTP id 673B012FBFE for ; Thu, 8 Mar 2012 14:21:25 +0000 (GMT) Received: from mail.allinea.com ([127.0.0.1]) by localhost (mail.allinea.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id dVHxhBuusiG8 for ; Thu, 8 Mar 2012 14:21:25 +0000 (GMT) Received: from [192.168.0.6] (cpc11-sotn9-2-0-cust158.15-1.cable.virginmedia.com [81.101.103.159]) (Authenticated sender: cjanuary) by mail.allinea.com (Postfix) with ESMTPSA id 0D3DE12FBFC for ; Thu, 8 Mar 2012 14:21:25 +0000 (GMT) Message-ID: <1331216484.2742.7.camel@gumtree> Subject: [PATCH] Fix incorrect use of strcpy. From: Chris January To: gdb-patches@sourceware.org Date: Thu, 08 Mar 2012 14:21:00 -0000 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit Mime-Version: 1.0 X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2012-03/txt/msg00264.txt.bz2 The strings passed to strcpy may not overlap, but &p and &p[len + 1] clearly do. memmove allows overlapping memory area. 2012-03-08 Chris January * source.c (add_path): Use memmove instead of strcpy because the strings overlap. --- diff --git a/gdb/source.c b/gdb/source.c index cfdf81b..7505309 100644 --- a/gdb/source.c +++ b/gdb/source.c @@ -588,7 +588,7 @@ add_path (char *dirname, char **which_path, int parse_separators) p--; /* Back over leading separator. */ if (prefix > p - *which_path) goto skip_dup; /* Same dir twice in one cmd. */ - strcpy (p, &p[len + 1]); /* Copy from next \0 or : */ + memmove (p, &p[len + 1], strlen(&p[len + 1]) + 1); /* Copy from next \0 or : */ } p = strchr (p, DIRNAME_SEPARATOR); if (p != 0)