Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Uninitialized strcpy in spname() for long strings
- X-seq: zsh-workers 28977
- From: Wayne Davison <wayned@xxxxxxxxxxxxxxxxxxxxx>
- To: Zsh list <zsh-workers@xxxxxxx>
- Subject: Uninitialized strcpy in spname() for long strings
- Date: Tue, 5 Apr 2011 16:54:30 -0700
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:sender:date:x-google-sender-auth :message-id:subject:from:to:content-type; bh=QWng/tCkuINeYJZmiQk9yPo7LFRxFrGpA8LFSOjOqOU=; b=n0SeExkGqP+GjMVAwOgvrRd/C+t500Nl1ciASFh6jRJaCVwHjkexrn1BSlrTnlCMuI UcdwA+uZwnllyucCayZscsJ5ZQtYK9hMSa4uoo/JVQzVmrSD0wQZU1D6Z9hhA2KQN0/V brzv6vkhxFOdK1fjL8Ee1uo9SY1yHsICl3MVU=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:date:x-google-sender-auth:message-id:subject :from:to:content-type; b=q/Kjt9Z+2zaAV2AJmTR/s8Xti46hbpJlZBvE46Zzv7LaFAp9jXebR6x6UCsa3rBRid jKqzE2fAmVqrfEGotzV05bTcZAix/aptnOfar6PRZIxkPNoBXY4lIp4//waFJRBPOreV KOKC62Bx2lorUIxodGc3Cfdug51ipYkwTQjc0=
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- Sender: 4wayned@xxxxxxxxx
I was testing a really long command-line arg to a program, and zsh
kept either prompting me for a corrupted correction, or crashing.
Turns out that the spname() function has a problem in it where a
really long path component (whether it really is or not) can cause the
thresh value to be larger than the maximum distance value that
mindist() can return, which causes spname() to copy an uninitialized
buffer (spnamebest). Several possible fixes come to mind:
- Set thresh to a maximum of 100, so the ">=" check will not think
mindist() succeeded when it failed.
- Skip the call to mindist() if the length of the string is greater
than NAME_MAX. At that max length, thresh can't be larger than the
maximal dist return (100 > 255/4+1).
Some combination of the two.
I'm attaching the simplest of the two changes which avoids the copying
of uninitialized memory. I'll check this in, and if anyone wants to
tweak it further, feel free.
..wayne..
index 9857303..22bffa2 100644
--- a/Src/utils.c
+++ b/Src/utils.c
@@ -3684,6 +3684,8 @@ spname(char *oldname)
thresh = (int)(p - spnameguess) / 4 + 1;
if (thresh < 3)
thresh = 3;
+ else if (thresh > 100)
+ thresh = 100;
if ((thisdist = mindist(newname, spnameguess, spnamebest)) >= thresh) {
/* The next test is always true, except for the first path *
* component. We could initialize bestdist to some large *
Messages sorted by:
Reverse Date,
Date,
Thread,
Author