From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29269 invoked by alias); 28 Feb 2011 11:55:27 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 28813 Received: (qmail 23744 invoked from network); 28 Feb 2011 11:55:23 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW, SPF_HELO_PASS autolearn=ham version=3.3.1 Received-SPF: none (ns1.primenet.com.au: domain at csr.com does not designate permitted sender hosts) Date: Mon, 28 Feb 2011 11:55:10 +0000 From: Peter Stephenson To: Subject: Re: PATCH: Fix multibyte memory allocation in `wcs_ztrdup()' Message-ID: <20110228115510.29590f1d@pwslap01u.europe.root.pri> In-Reply-To: <1298889300-29679-1-git-send-email-ft@bewatermyfriend.org> References: <1298889300-29679-1-git-send-email-ft@bewatermyfriend.org> Organization: Cambridge Silicon Radio X-Mailer: Claws Mail 3.7.8 (GTK+ 2.22.0; i386-redhat-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.103.11.49] X-Scanned-By: MailControl A_10_80_00 (www.mailcontrol.com) on 10.71.0.132 On Mon, 28 Feb 2011 11:35:00 +0100 Frank Terbeck wrote: > This was spotted by Thorsten Glaser from the mirbsd project. > > `zalloc()' uses malloc(3) to allocate memory. wcslen(3) returns the > number of multibyte *characters* in a given string (N). The > destination string will have to be able to store N+1 wchar_ts, not > N+1 bytes. Thanks... and it needs to be a wide NULL (L'0'), too, so another lot of parentheses is needed. Index: Src/string.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/string.c,v retrieving revision 1.10 diff -p -u -r1.10 string.c --- Src/string.c 6 Jul 2007 21:52:39 -0000 1.10 +++ Src/string.c 28 Feb 2011 11:51:46 -0000 @@ -64,7 +64,7 @@ wcs_ztrdup(const wchar_t *s) if (!s) return NULL; - t = (wchar_t *)zalloc(wcslen((wchar_t *)s) + 1); + t = (wchar_t *)zalloc(sizeof(wchar_t) * (wcslen((wchar_t *)s) + 1)); wcscpy(t, s); return t; } -- Peter Stephenson Software Engineer Tel: +44 (0)1223 692070 Cambridge Silicon Radio Limited Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, UK Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom