summaryrefslogtreecommitdiff
path: root/source3/lib
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2007-05-07 19:27:46 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 12:21:54 -0500
commit798af9e0c86976245c36ea1f0c7171e9ab663da7 (patch)
treeced29fd33c791cf09617a4883e7050730380dfa5 /source3/lib
parent76ce309234adbe0a6a56b849a91714cab148c4a7 (diff)
downloadsamba-798af9e0c86976245c36ea1f0c7171e9ab663da7.tar.gz
samba-798af9e0c86976245c36ea1f0c7171e9ab663da7.tar.bz2
samba-798af9e0c86976245c36ea1f0c7171e9ab663da7.zip
r22754: When processing a string, ensure we don't write one past
the terminating NULL if we've already processed the null in iconv. Jerry, once I get confirmation from Thomas Bork this needs to be in 3.0.25 final. Tests fine with valgrind here. Jeremy. (This used to be commit 14b167ef6e0f2100bd9cdd05c4457e57e952fa5e)
Diffstat (limited to 'source3/lib')
-rw-r--r--source3/lib/charcnv.c21
1 files changed, 15 insertions, 6 deletions
diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c
index 3d02988a97..8d5fbc8118 100644
--- a/source3/lib/charcnv.c
+++ b/source3/lib/charcnv.c
@@ -972,13 +972,18 @@ size_t pull_ascii(char *dest, const void *src, size_t dest_len, size_t src_len,
ret = convert_string(CH_DOS, CH_UNIX, src, src_len, dest, dest_len, True);
if (ret == (size_t)-1) {
+ ret = 0;
dest_len = 0;
}
- if (dest_len)
- dest[MIN(ret, dest_len-1)] = 0;
- else
+ if (dest_len && ret) {
+ /* Did we already process the terminating zero ? */
+ if (dest[MIN(ret-1, dest_len-1)] != 0) {
+ dest[MIN(ret, dest_len-1)] = 0;
+ }
+ } else {
dest[0] = 0;
+ }
return src_len;
}
@@ -1219,10 +1224,14 @@ size_t pull_ucs2(const void *base_ptr, char *dest, const void *src, size_t dest_
if (src_len == (size_t)-1)
src_len = ret*2;
- if (dest_len)
- dest[MIN(ret, dest_len-1)] = 0;
- else
+ if (dest_len && ret) {
+ /* Did we already process the terminating zero ? */
+ if (dest[MIN(ret-1, dest_len-1)] != 0) {
+ dest[MIN(ret, dest_len-1)] = 0;
+ }
+ } else {
dest[0] = 0;
+ }
return src_len;
}