From patchwork Thu Mar 27 19:22:54 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ondrej Bilka X-Patchwork-Id: 319 Return-Path: X-Original-To: siddhesh@wilcox.dreamhost.com Delivered-To: siddhesh@wilcox.dreamhost.com Received: from homiemail-mx23.g.dreamhost.com (caibbdcaabja.dreamhost.com [208.113.200.190]) by wilcox.dreamhost.com (Postfix) with ESMTP id CA60036055A for ; Thu, 27 Mar 2014 12:23:08 -0700 (PDT) Received: by homiemail-mx23.g.dreamhost.com (Postfix, from userid 14307373) id 7A3A6620B602B; Thu, 27 Mar 2014 12:23:08 -0700 (PDT) X-Original-To: glibc@patchwork.siddhesh.in Delivered-To: x14307373@homiemail-mx23.g.dreamhost.com Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by homiemail-mx23.g.dreamhost.com (Postfix) with ESMTPS id 5598A620B601D for ; Thu, 27 Mar 2014 12:23:08 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:from:to:cc:subject:message-id:references :mime-version:content-type:in-reply-to; q=dns; s=default; b=oDwu HgvmPHwaY4uKo5vnahodewcrvwDTxu7091lExZRTRbQBL9uxAV72xQ/kfJeqcMSQ zzcuTKQOsGJFfc02ltHrO5fCfQWWpnHMlH+mQxsOZx7dAIjXKhBHj33i5qTGo141 kuvk696m1yKduBEU8p/LLR9hO71LaRYqVJYojAY= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:from:to:cc:subject:message-id:references :mime-version:content-type:in-reply-to; s=default; bh=8kTMF3OvnW mBqPKrheERm+LghiQ=; b=hUh+vpSb+/yn8DCh1zKv44eDqhaB656LjfGaFErUGo evo44KYHTA1P+XlrAEYqK3D2mxH6i6lQglQbbWVAJ84hA/F5ND4KNozq3hda/PsP lKVa1q4ECOFjCRopcAkWmuCvbNSGwpdUpe1XnVXo6feN/Kp01fQaVLjHQdUpv7Ss A= Received: (qmail 12655 invoked by alias); 27 Mar 2014 19:23:06 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 12640 invoked by uid 89); 27 Mar 2014 19:23:05 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.6 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, SPF_NEUTRAL autolearn=no version=3.3.2 X-HELO: popelka.ms.mff.cuni.cz Date: Thu, 27 Mar 2014 20:22:54 +0100 From: =?utf-8?B?T25kxZllaiBCw61sa2E=?= To: Mike Frysinger Cc: libc-alpha@sourceware.org, Siddhesh Poyarekar Subject: Re: [PATCH] Avoid overlapping addresses to stpcpy calls in nscd (BZ #16760) Message-ID: <20140327192254.GC1982@domone.podge> References: <20140327040406.GA26264@spoyarek.pnq.redhat.com> <1499542.yzGAIksTkn@vapier> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1499542.yzGAIksTkn@vapier> User-Agent: Mutt/1.5.20 (2009-06-14) X-DH-Original-To: glibc@patchwork.siddhesh.in On Thu, Mar 27, 2014 at 03:34:11AM -0400, Mike Frysinger wrote: > On Thu 27 Mar 2014 09:34:06 Siddhesh Poyarekar wrote: > > Calls to stpcpy from nscd netgroups code will have overlapping source > > and destination when all three values in the returned triplet are > > non-NULL and in the expected (host,user,domain) order. This is seen > > in valgrind as: > > > > Fix this by using memmove instead of stpcpy. Tested x86_64 using > > various combinations of triplets (including NULL and non-NULL ones) to > > verify that this works correctly and there are no regressions. > This could work only with additional assertion that we do not move host forward otherwise it could overwrite user. > i feel like we've wanted an equivalent of stpcpy/memccpy for memmove. good > time to add it ? :) > Yes, it would be better to use this at least internally, perhaps this patch instead is cleaner. Other possibility is keep these in separate header like second snippet, do you have better name for that? Also I could make a stpcat and move equivalent, not sure with what name. Her I would fix a root cause of these bugs which is bad design. We mix temporary buffer with building result. If we use separate buffers for that a code would be lot simpler, I will prepare patch for it. diff --git a/string/extension.h b/string/extension.h new file mode 100644 index 0000000..963dccf --- /dev/null +++ b/string/extension.h @@ -0,0 +1,36 @@ +/* Copyright (C) 2014 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + + +#ifndef _STRING_EXTENSION_H +#define _STRING_EXTENSION_H 1 + +#include +#include + + +static inline +char * +stpmove (char *dest, const char *src) +{ + size_t len = strlen (src); + memmove (dest, src, len); + return dest + len; +} + + +#endif