From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18392 invoked from network); 4 May 2004 14:42:47 -0000 Received: from thor.dotsrc.org (HELO a.mx.sunsite.dk) (qmailr@130.225.247.86) by ns1.primenet.com.au with SMTP; 4 May 2004 14:42:47 -0000 Received: (qmail 19546 invoked from network); 4 May 2004 14:42:32 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 4 May 2004 14:42:32 -0000 Received: (qmail 29260 invoked by alias); 4 May 2004 14:42:29 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 19875 Received: (qmail 29250 invoked from network); 4 May 2004 14:42:29 -0000 Received: from thor.dotsrc.org (HELO a.mx.sunsite.dk) (qmailr@130.225.247.86) by sunsite.dk with SMTP; 4 May 2004 14:42:26 -0000 Received: (qmail 19394 invoked from network); 4 May 2004 14:42:26 -0000 Received: from lhuumrelay3.lnd.ops.eu.uu.net (62.189.58.19) by a.mx.sunsite.dk with SMTP; 4 May 2004 14:42:24 -0000 Received: from MAILSWEEPER01.csr.com (mailhost1.csr.com [62.189.183.235]) by lhuumrelay3.lnd.ops.eu.uu.net (8.11.0/8.11.0) with ESMTP id i44Efvv08602 for ; Tue, 4 May 2004 14:41:57 GMT Received: from EXCHANGE02.csr.com (unverified [192.168.137.45]) by MAILSWEEPER01.csr.com (Content Technologies SMTPRS 4.3.12) with ESMTP id ; Tue, 4 May 2004 15:41:27 +0100 Received: from csr.com ([192.168.144.127]) by EXCHANGE02.csr.com with Microsoft SMTPSVC(5.0.2195.6713); Tue, 4 May 2004 15:43:14 +0100 To: zsh-workers@sunsite.dk, 245974@bugs.debian.org Subject: Re: Bug#245974: zsh: export LC_ALL=da_DK causes segfault In-reply-to: "Peter Stephenson"'s message of "Tue, 04 May 2004 10:26:03 BST." <14327.1083662763@csr.com> Date: Tue, 04 May 2004 15:41:56 +0100 Message-ID: <13948.1083681716@csr.com> From: Peter Stephenson X-OriginalArrivalTime: 04 May 2004 14:43:14.0097 (UTC) FILETIME=[211C7A10:01C431E6] X-Spam-Checker-Version: SpamAssassin 2.63 on a.mx.sunsite.dk X-Spam-Level: X-Spam-Status: No, hits=0.0 required=6.0 tests=BAYES_50 autolearn=no version=2.63 X-Spam-Hits: 0.0 Peter Stephenson wrote: > Clint Adams wrote: > > > Seems that when LC_TIME (or LC_ALL or LANG) is set to a locale such as > > > da_DK or de_DE, wherein am_pm is set to null strings, zsh will segfault > > > upon prompt-expanding %p or %P. Seems that the first argument to > > > > So, when am_pm is set to null strings, strftime() with format "%p" or > > "%P" will return 0, which zsh is ill-equipped to handle. > > The following patch avoids the segfault. I hope there's a better way to > > do this. > > Yes, the right way to do it is to handle `0' properly, which says the > array is in an indeterminate state and hence the shell should tidy up. > The current patch is not the right way to do it. This is a better patch, although it's not ideal, owing to the interface of strftime which doesn't signal success or failure properly. In general, please don't commit gross hacks to the archive unless they are strictly necessary, since it just makes extra work later. In this case, the new hack was just disguising the fact that the previous hack was allocating infinite amounts of memory without an exit test. It's not surprising the shell code is less than transparent in a lot of places. The second hunk is a bit imperfect, too, for the same reason --- well, actually we could be smarter in returns from ztrftime than from strftime, but at the moment we aren't --- but will at least ensure the buffer is correctly terminated in cases like the present one. Index: Src/prompt.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/prompt.c,v retrieving revision 1.16 diff -u -r1.16 prompt.c --- Src/prompt.c 4 May 2004 04:17:29 -0000 1.16 +++ Src/prompt.c 4 May 2004 14:34:47 -0000 @@ -526,11 +526,16 @@ } timet = time(NULL); tm = localtime(&timet); - for(t0=80; ; t0*=2) { + /* + * Ghastly hack because strftime won't say how + * much space it actually needs. Try to add it + * a few times until it works. Some formats don't + * actually have a length, so we could go on for + * ever. + */ + for(j = 0, t0 = strlen(tmfmt)*8; j < 3; j++, t0*=2) { addbufspc(t0); - if (ztrftime(bp, t0, tmfmt, tm) || - !strcmp("%P", tmfmt) || - !strcmp("%p", tmfmt)) + if (ztrftime(bp, t0, tmfmt, tm)) break; } bp += strlen(bp); Index: Src/utils.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/utils.c,v retrieving revision 1.59 diff -u -r1.59 utils.c --- Src/utils.c 4 May 2004 04:17:29 -0000 1.59 +++ Src/utils.c 4 May 2004 14:34:48 -0000 @@ -1831,9 +1831,11 @@ */ *buf = '\0'; tmp[1] = fmt[-1]; - if (!strftime(buf, bufsize + 2, tmp, tm) && - tmp[1]!='p' && tmp[1]!='P') + if (!strftime(buf, bufsize + 2, tmp, tm)) + { + buf[0] = '\0'; return 0; + } decr = strlen(buf); buf += decr; bufsize -= decr - 2; -- Peter Stephenson Software Engineer CSR Ltd., Science Park, Milton Road, Cambridge, CB4 0WH, UK Tel: +44 (0)1223 692070 ********************************************************************** This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please notify the system manager. This footnote also confirms that this email message has been swept by MIMEsweeper for the presence of computer viruses. www.mimesweeper.com **********************************************************************