zsh-workers
 help / color / mirror / code / Atom feed
* paramsubst bug
@ 1997-06-16 18:33 Zefram
  0 siblings, 0 replies; only message in thread
From: Zefram @ 1997-06-16 18:33 UTC (permalink / raw)
  To: zsh-workers

-----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-----


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~1997-06-16 18:47 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-06-16 18:33 paramsubst bug Zefram

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).