zsh-workers
 help / color / mirror / code / Atom feed
From: Zefram <zefram@dcs.warwick.ac.uk>
To: zsh-workers@math.gatech.edu
Subject: paramsubst bug
Date: Mon, 16 Jun 1997 19:33:56 +0100 (BST)	[thread overview]
Message-ID: <8796.199706161833@stone.dcs.warwick.ac.uk> (raw)

-----BEGIN PGP SIGNED MESSAGE-----

% zsh <<< '
    set a b c d e
    echo "$@"
    set "$@"
    echo "$@"
  ' | cat -v
a b c d e
a HM-^B^N^HPM-^B^N^H M-x[^N^H@M-^B^N^Hks PM-^B^N^H0M-^B^N^HM-0M-^A^N^HM-x[^N^HM-x[^N^H@M-^B^N^Hks e

The bug is that the substitution of `"$@"' returns the original strings
from pparams, rather than duplicating them.  bin_set() frees pparams and
then duplicates its arguments -- but freeing pparams also freed some of
its arguments.  set has had this behaviour that tickles this bug since
3.0.1-test, but the subst.c code is far older and there are undoubtedly
other ways in which in can cause wrong behaviour.

I think the correct solution is for paramsubst() to always duplicate the
strings, rather than attempting this optimisation.  The patch below fixes
the array case, but there are very many code paths and I'm not sure if
any others might fail to duplicate.  (Look at the `copied' variable.)
We could do with some comments in subst.c to indicate which functions
can return their arguments unmodified.

This patch applies to both 3.1.2 and 3.0.3.

 -zefram

 *** Src/subst.c	1997/06/14 00:25:43	1.29
 --- Src/subst.c	1997/06/16 14:03:41
 ***************
 *** 1453,1462 ****
   		    return NULL;
   		if (qt && !*x && isarr != 2)
   		    y = dupstring(nulstring);
 ! 		else if (globsubst)
 ! 		    tokenize(y = dupstring(x));
 ! 		else
 ! 		    y = x;
   		insertlinknode(l, n, (void *) y), incnode(n);
   	    }
   
 --- 1453,1463 ----
   		    return NULL;
   		if (qt && !*x && isarr != 2)
   		    y = dupstring(nulstring);
 ! 		else {
 ! 		    y = dupstring(x);
 ! 		    if (globsubst)
 ! 			tokenize(y);
 ! 		}
   		insertlinknode(l, n, (void *) y), incnode(n);
   	    }
   

-----BEGIN PGP SIGNATURE-----
Version: 2.6.3ia
Charset: ascii

iQEUAwUBM6VKHJmk9GeOHh7BAQH8TQf2PWpPMTKm0JjalDwMxFBeWkRJOTsMAllI
ROeaTAhg6aULvbCIMBj/8hHWIz76/FA+ihaEkRQqFGm9QIa3VS1xmy+CE3+XoXH9
satQ5KUzabGL6doKrakb2v14ALrQZVCYKt7Mb4UeWU+FadMLtA0QeKp7XUBfMpNf
ijh+x1bUnrHymyVuE0zFzrCbFubhcQ3U/BZNRNBSPntAQM5KHXN6t9WiBXzHzaPr
RBbMTJPKzAPecPxXO2kgPA7Z5Qs2QcpPbg4/gCuNBEG4bPRPen/RziDpF6wzkTi8
kCThXm5Wk2wavQDgM6Vzb72FxA6jnmj/i+sQZIL9kFS7cU658gP3
=NbPr
-----END PGP SIGNATURE-----


                 reply	other threads:[~1997-06-16 18:47 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8796.199706161833@stone.dcs.warwick.ac.uk \
    --to=zefram@dcs.warwick.ac.uk \
    --cc=zsh-workers@math.gatech.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).