On December 21, 2014 5:12:33 AM CST, James Humphrey <[email protected]> wrote:
>
> I have found a strange behavior while using aliases in the shell. I'm
> wondering if someone can provide an explanation for the error below.
I was curious, so I built /usr/bin/ksh with debugging symbols on 5.6-stable.
The error seems to be occurring when malloc() fails when ksh exhausts its
available memory. A stack trace suggests that this is occurring within a
possibly logically-recursive backtick expansion. A bit of experimentation (see
below) suggests that both a pre-existing alias with the same name and the use
of backticks are prerequisites.
I leave it to someone with more ksh expertise to say what the defined behavior
should be in this case. I'm not sure I see a useful real-world scenario where
this would be triggered. But if it is, you can prevent it by running `unalias
ls' before setting the alias using backtick expansion.
The non-pdksh implementation on CentOS 6 accepts this construct and behaves as
you seem to expect (perhaps it processes the backtick expansion before the
alias creation?):
$ alias ls='ls'
$ alias ls=`ls`
$ ls
ksh: access-logs: not found [No such file or directory]
--------
Here is the backtrace from 5.6-stable:
--------
(gdb) run
The program being debugged has been started already.
Start it from the beginning? (y or n) y
Starting program: /home/case/DEV/ksh/obj/ksh
$ alias whizbang=`whizbang`
[New process 27016]
/home/case/DEV/ksh/obj/ksh: whizbang: not found
$ alias whizbang='date'
$ alias whizbang=`whizbang`
$ alias date=`date`
$ unalias date
$ alias date='date'
$ alias date=`date`
[time passes and memory usage increases]
^C
Program received signal SIGINT, Interrupt.
alloc (size=64, ap=0x890e5f0c) at /usr/src/bin/ksh/alloc.c:69
69 l->prev = NULL;
(gdb) bt
#0 alloc (size=64, ap=0x890e5f0c) at /usr/src/bin/ksh/alloc.c:69
#1 0x1a224850 in pushs (type=7, areap=0x890e5f0c)
at /usr/src/bin/ksh/lex.c:924
#2 0x1a225c97 in yylex (cf=Variable "cf" is not available.
) at /usr/src/bin/ksh/lex.c:813
#3 0x1a22efa7 in get_command (cf=44) at /usr/src/bin/ksh/syn.c:206
#4 0x1a22e7bb in pipeline (cf=Variable "cf" is not available.
) at /usr/src/bin/ksh/syn.c:77
#5 0x1a22e8ac in c_list (multi=1) at /usr/src/bin/ksh/syn.c:98
#6 0x1a22ff47 in compile (s=0x890e5688) at /usr/src/bin/ksh/syn.c:64
#7 0x1a2185a7 in expand (cp=0x7ac72cc8 "\001d\001a\001t\001e\001=\003date",
wp=0xcfbccf1c, f=Variable "f" is not available.
) at /usr/src/bin/ksh/eval.c:850
#8 0x1a21967b in eval (ap=0x80c0f98c, f=523) at /usr/src/bin/ksh/eval.c:86
#9 0x1a21ae8b in execute (t=0x84454748, flags=0, xerrok=0xcfbcd044)
at /usr/src/bin/ksh/exec.c:77
#10 0x1a2282ba in shell (s=0x83ea9a88, toplevel=1)
at /usr/src/bin/ksh/main.c:595
#11 0x1a228e92 in main (argc=0, argv=0xcfbcd274) at /usr/src/bin/ksh/main.c:400
(gdb)
--------
Regards,
[email protected]