From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gatech.edu (gatech.edu [130.207.244.244]) by werple.mira.net.au (8.6.12/8.6.9) with SMTP id BAA29163 for ; Thu, 17 Aug 1995 01:34:03 +1000 Received: from math (math.skiles.gatech.edu) by gatech.edu with SMTP id AA02212 (5.65c/Gatech-10.0-IDA for ); Wed, 16 Aug 1995 11:27:39 -0400 Received: by math (5.x/SMI-SVR4) id AA16473; Wed, 16 Aug 1995 11:22:12 -0400 Resent-Date: Wed, 16 Aug 1995 17:20:19 +0200 (MET DST) Old-Return-Path: From: Zoltan Hidvegi Message-Id: <199508161523.RAA22132@bolyai.cs.elte.hu> Subject: Re: hzoli change: $foo:s//r/ To: kaefer@aglaia.snafu.de (Thorsten Meinecke) Date: Wed, 16 Aug 1995 17:20:19 +0200 (MET DST) In-Reply-To: from "Thorsten Meinecke" at Aug 16, 95 04:49:30 pm X-Mailer: ELM [version 2.4 PL24] Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: hzoli@cs.elte.hu Resent-Message-Id: <"-09VT1.0.J14.ZqWCm"@math> Resent-From: zsh-workers@math.gatech.edu X-Mailing-List: archive/latest/323 X-Loop: zsh-workers@math.gatech.edu Precedence: list Resent-Sender: zsh-workers-request@math.gatech.edu > > Another very minor problem with Zoltan's substitution code. > > If hsubr is non-NULL, and a "bad/no previous substitution" error > occurs, hsubr is free()d. This may corrupt memory. Example: > > $ PS1='[%!] ' ./zsh -f > [1] echo $foo:s/x// > > [2] echo $foo:s/ // > zsh: bad substitution > [3] echo $foo:s/ // > zsh: attempt to free already free storage > > This fix only free()s hsubr when there was *no* error. You are right here. But there is an other problem: the code assumes in many places that extern variables are initialized to zero. If hsubl/hsubr were not zero on startup it would cause the same problem even after this patch. The patch below initializes hsubl/hsubr in globals.h and probably there are some other variables which require similar treatment. Zoltan *** 1.10 1995/07/24 17:12:46 --- Src/globals.h 1995/08/14 17:09:11 *************** *** 36,43 **** --- 36,45 ---- #ifdef GLOBALS # define EXTERN + # define CHARPTR(X) char *X = NULL; #else # define EXTERN extern + # define CHARPTR(X) extern char *X; #endif #ifdef GLOBALS *************** *** 284,294 **** /* the last l for s/l/r/ history substitution */ ! EXTERN char *hsubl; /* the last r for s/l/r/ history substitution */ ! EXTERN char *hsubr; /* We cache `USERNAME' and use check cached_uid * * so we know when to recompute it. */ --- 286,296 ---- /* the last l for s/l/r/ history substitution */ ! CHARPTR(hsubl) /* the last r for s/l/r/ history substitution */ ! CHARPTR(hsubr) /* We cache `USERNAME' and use check cached_uid * * so we know when to recompute it. */