From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/8 Path: news.gmane.org!not-for-mail From: Szabolcs Nagy Newsgroups: gmane.linux.lib.musl.general Subject: wcsncpy bug Date: Mon, 23 May 2011 03:25:47 +0200 Message-ID: <20110523012547.GH6142@port70.net> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="ucfHZChuBC0NsER/" X-Trace: dough.gmane.org 1306113976 11158 80.91.229.12 (23 May 2011 01:26:16 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Mon, 23 May 2011 01:26:16 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-91-gllmg-musl=m.gmane.org@lists.openwall.com Mon May 23 03:26:12 2011 Return-path: Envelope-to: gllmg-musl@lo.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by lo.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1QOJuN-0006Am-AL for gllmg-musl@lo.gmane.org; Mon, 23 May 2011 03:26:11 +0200 Original-Received: (qmail 6119 invoked by uid 550); 23 May 2011 01:26:10 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Original-Received: (qmail 6111 invoked from network); 23 May 2011 01:26:10 -0000 Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) Xref: news.gmane.org gmane.linux.lib.musl.general:8 Archived-At: --ucfHZChuBC0NsER/ Content-Type: text/plain; charset=us-ascii Content-Disposition: inline wcsncpy(d,s,n) did not decrease n while copying the '\0' so when s[0]=0 and n=1 it wrote 2 zeros to d --ucfHZChuBC0NsER/ Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="wcsncpy.diff" diff --git a/src/string/wcsncpy.c b/src/string/wcsncpy.c index 0164208..fbd0631 100644 --- a/src/string/wcsncpy.c +++ b/src/string/wcsncpy.c @@ -3,7 +3,7 @@ wchar_t *wcsncpy(wchar_t *d, const wchar_t *s, size_t n) { wchar_t *a = d; - while (n && (*d++ = *s++)) n--; + while (n-- && (*d++ = *s++)); wmemset(d, 0, n); return a; } --ucfHZChuBC0NsER/--