diff options
author | Alexander Bokovoy <ab@samba.org> | 2008-02-06 08:58:20 +0300 |
---|---|---|
committer | Alexander Bokovoy <ab@samba.org> | 2008-02-06 08:58:20 +0300 |
commit | d022ed3eecbe4c3bd0c93ee09608c43048e6881a (patch) | |
tree | e1d22eead92455edbcccbd291694bf7354b83b5b /source3/lib/charcnv.c | |
parent | d3ee93596f574be2d0263efb92b2c38cf47a1a9d (diff) | |
parent | b3f48266f353fb93fee35bdcadaec3abc0fe0122 (diff) | |
download | samba-d022ed3eecbe4c3bd0c93ee09608c43048e6881a.tar.gz samba-d022ed3eecbe4c3bd0c93ee09608c43048e6881a.tar.bz2 samba-d022ed3eecbe4c3bd0c93ee09608c43048e6881a.zip |
Merge branch 'v3-2-test' of ssh://git.samba.org/data/git/samba into dmapi-integration
(This used to be commit f59d3786abcc53065c838a2fa82ec2f4b577b16f)
Diffstat (limited to 'source3/lib/charcnv.c')
-rw-r--r-- | source3/lib/charcnv.c | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index eeff805459..d11620ecd7 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -524,7 +524,7 @@ size_t convert_string(charset_t from, charset_t to, size_t convert_string_allocate(TALLOC_CTX *ctx, charset_t from, charset_t to, void const *src, size_t srclen, void *dst, bool allow_bad_conv) { - size_t i_len, o_len, destlen = MAX(srclen, 512); + size_t i_len, o_len, destlen = (srclen * 3) / 2; size_t retval; const char *inbuf = (const char *)src; char *outbuf = NULL, *ob = NULL; @@ -550,7 +550,8 @@ size_t convert_string_allocate(TALLOC_CTX *ctx, charset_t from, charset_t to, convert: - if ((destlen*2) < destlen) { + /* +2 is for ucs2 null termination. */ + if ((destlen*2)+2 < destlen) { /* wrapped ! abort. */ if (!conv_silent) DEBUG(0, ("convert_string_allocate: destlen wrapped !\n")); @@ -561,10 +562,11 @@ size_t convert_string_allocate(TALLOC_CTX *ctx, charset_t from, charset_t to, destlen = destlen * 2; } + /* +2 is for ucs2 null termination. */ if (ctx) { - ob = (char *)TALLOC_REALLOC(ctx, ob, destlen); + ob = (char *)TALLOC_REALLOC(ctx, ob, destlen + 2); } else { - ob = (char *)SMB_REALLOC(ob, destlen); + ob = (char *)SMB_REALLOC(ob, destlen + 2); } if (!ob) { @@ -619,10 +621,11 @@ size_t convert_string_allocate(TALLOC_CTX *ctx, charset_t from, charset_t to, * reallocs *cost*. JRA. */ if (o_len > 1024) { + /* We're shrinking here so we know the +2 is safe from wrap. */ if (ctx) { - ob = (char *)TALLOC_REALLOC(ctx,ob,destlen); + ob = (char *)TALLOC_REALLOC(ctx,ob,destlen + 2); } else { - ob = (char *)SMB_REALLOC(ob,destlen); + ob = (char *)SMB_REALLOC(ob,destlen + 2); } } @@ -632,6 +635,11 @@ size_t convert_string_allocate(TALLOC_CTX *ctx, charset_t from, charset_t to, } *dest = ob; + + /* Must ucs2 null terminate in the extra space we allocated. */ + ob[destlen] = '\0'; + ob[destlen+1] = '\0'; + return destlen; use_as_is: |