zsh-workers
 help / color / mirror / code / Atom feed
From: Thorsten Meinecke <kaefer@aglaia.snafu.DE>
To: zsh-workers@math.gatech.edu
Cc: hniksic@gnjilux.cc.fer.hr
Subject: Re: compctl bug with beta17 on Linux
Date: Thu, 9 May 1996 01:51:15 +0200 (MET DST)	[thread overview]
Message-ID: <m0uHJ0o-00008aC@aglaia.snafu.DE> (raw)
In-Reply-To: <199605080944.LAA04529@gnjilux.cc.fer.hr> from "Hrvoje Niksic" at May 8, 96 11:44:30 am

In <zsh-workers@math.gatech.edu> archive/latest/1007,
Hrvoje Niksic <hniksic@gnjilux.cc.fer.hr> wrote:

> compctl -g '*(D-/)' cd
> cd /home/p[TAB]

[beta17 dumps core, if there's no file/dir named p* in /home]

I was able to reproduce this bug on my Linux-box.

> gdb shows that the shell fails in zle_tricky.c, in the second call of
> get_ccompctl, where the cmdstr contains garbage (instead of "cd"), and
> causes declaration char *cmd = dupstring(cmdstr) to coredump in strcpy.

Is this condition likely to occur?  SIGSEGV caused by overlapping
strings in strcpy().  That may explain why this bug went by unnoticed
for such a long time.

> Further analysis shows that cmdstr (or at least the contents of the memory
> it points to) gets garbled when newlinklist() is called

That's close.  You were lucky that the memory cmdstr pointed to wasn't
corrupted in the first place.  I do not claim that I understand even a
small percentage of what is going on in zle_tricky, but it looks like
there went something wrong with heap allocation in regard to cmdstr.

Assignments to cmdstr happen one or more times in get_comp_string(), de-
pending on the lexer's output.  The command strings found are stored onto
the current heap, and only the last (that is, innermost) one found will
be used subsequently.  But before anything useful can be done with cmdstr,
the heap will be released! 

That prompts my idea of the fix: simply make the string that cmdstr points
to permanent and free it when we are done.  Can somebody more proficient in
zle_tricky hacking comment on the risk of introducing a memory leak here?

Regards, Thorsten


*** 2.25	1996/05/05 10:06:07
--- zle_tricky.c	1996/05/08 19:00:49
***************
*** 575,582 ****
--- 575,583 ----
  	we -= chl;
  	if (wb < 0 || we < 0)
  	    return;
      }
+     cmdstr = ztrdup(cmdstr);
      freeheap();
      /* Save the lexer state, in case the completion code uses the lexer
         somewhere (e.g. when processing a compctl -s flag). */
      lexsave();
***************
*** 733,740 ****
--- 734,742 ----
      }
      /* Reset the lexer state, pop the heap. */
      lexrestore();
      popheap();
+     zsfree(cmdstr);
      zsfree(qword);
      menuce = complexpect;
  }
  



  reply	other threads:[~1996-05-09  0:06 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-05-08  9:44 Hrvoje Niksic
1996-05-08 23:51 ` Thorsten Meinecke [this message]
1996-05-09  0:05 ` Zoltan Hidvegi
1996-05-09 14:15   ` Thorsten Meinecke
1996-05-09 21:01     ` Zoltan Hidvegi

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=m0uHJ0o-00008aC@aglaia.snafu.DE \
    --to=kaefer@aglaia.snafu.de \
    --cc=hniksic@gnjilux.cc.fer.hr \
    --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).