From: Peter Stephenson <p.stephenson@samsung.com>
To: zsh-workers@zsh.org
Subject: Re: Zsh parser malloc corruption
Date: Thu, 11 May 2017 17:15:38 +0100 [thread overview]
Message-ID: <20170511171538.7824aed0@pwslap01u.europe.root.pri> (raw)
In-Reply-To: <170509232141.ZM7753@torch.brasslantern.com>
On Tue, 9 May 2017 23:21:41 -0700
Bart Schaefer <schaefer@brasslantern.com> wrote:
> PWS, I'm going to ask you to please look at this after all, because it
> seems to be related to
>
> 36682: expand pattern interface to optimise unmetafication
>
> Valgrind says:
>
> ==19116== Invalid write of size 1
> ==19116== at 0x4A2E0D: patcompile (pattern.c:679)
Doesn't seem easy to reproduce --- probably due to malloc library
variabilities and/or uninitialised memory --- but when I managed to get
it to happen it reported an error a few lines earlier.
Does the following help? I think it's needed in any case --- we can't
use strcpy() on unmetafied strings as they are there partly to allow us
to treat embedded nulls as normal characters. It's also pointless
and inconsistent testing for a NULL termination in a function with the
length passed in.
pws
diff --git a/Src/string.c b/Src/string.c
index a8da14f..9e14ef9 100644
--- a/Src/string.c
+++ b/Src/string.c
@@ -52,7 +52,8 @@ dupstring_wlen(const char *s, unsigned len)
if (!s)
return NULL;
t = (char *) zhalloc(len + 1);
- strcpy(t, s);
+ memcpy(t, s, len);
+ t[len] = '\0';
return t;
}
next prev parent reply other threads:[~2017-05-11 16:25 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CGME20170508135522epcas1p2c81789e7cafaa2c46e00eed1472af895@epcas1p2.samsung.com>
2017-05-08 13:53 ` Eduardo Bustamante
2017-05-08 14:11 ` Peter Stephenson
2017-05-08 14:16 ` Eduardo Bustamante
2017-05-08 14:20 ` Eduardo Bustamante
2017-05-08 15:10 ` Peter Stephenson
2017-05-08 19:12 ` Daniel Shahaf
2017-05-10 6:21 ` Bart Schaefer
2017-05-11 16:15 ` Peter Stephenson [this message]
2017-05-11 21:09 ` Bart Schaefer
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=20170511171538.7824aed0@pwslap01u.europe.root.pri \
--to=p.stephenson@samsung.com \
--cc=zsh-workers@zsh.org \
/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).