From: Frank Terbeck <ft@bewatermyfriend.org>
To: zsh-workers@zsh.org
Subject: PATCH: Fix multibyte memory allocation in `wcs_ztrdup()'
Date: Mon, 28 Feb 2011 11:35:00 +0100 [thread overview]
Message-ID: <1298889300-29679-1-git-send-email-ft@bewatermyfriend.org> (raw)
This was spotted by Thorsten Glaser from the mirbsd project.
`zalloc()' uses malloc(3) to allocate memory. wcslen(3) returns the
number of multibyte *characters* in a given string (N). The destination
string will have to be able to store N+1 wchar_ts, not N+1 bytes.
Regards, Frank
---
Src/string.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/Src/string.c b/Src/string.c
index 2bd1bae..4d74aa0 100644
--- a/Src/string.c
+++ b/Src/string.c
@@ -64,7 +64,7 @@ wcs_ztrdup(const wchar_t *s)
if (!s)
return NULL;
- t = (wchar_t *)zalloc(wcslen((wchar_t *)s) + 1);
+ t = (wchar_t *)zalloc(sizeof(wchar_t) * wcslen((wchar_t *)s) + 1);
wcscpy(t, s);
return t;
}
--
1.7.4.rc1.7.g2cf08
next reply other threads:[~2011-02-28 10:36 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-02-28 10:35 Frank Terbeck [this message]
2011-02-28 11:55 ` Peter Stephenson
2011-02-28 12:04 ` Frank Terbeck
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=1298889300-29679-1-git-send-email-ft@bewatermyfriend.org \
--to=ft@bewatermyfriend.org \
--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).