summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/util/charset/charcnv.c11
-rw-r--r--lib/util/charset/charset.h11
-rw-r--r--lib/util/charset/tests/iconv.c6
-rw-r--r--lib/util/charset/util_unistr.c31
4 files changed, 34 insertions, 25 deletions
diff --git a/lib/util/charset/charcnv.c b/lib/util/charset/charcnv.c
index 1f3b1ac846..18be2bcac2 100644
--- a/lib/util/charset/charcnv.c
+++ b/lib/util/charset/charcnv.c
@@ -240,7 +240,7 @@ convert:
_PUBLIC_ ssize_t convert_string_convenience(struct smb_iconv_convenience *ic,
charset_t from, charset_t to,
void const *src, size_t srclen,
- void *dest, size_t destlen)
+ void *dest, size_t destlen, bool allow_badcharcnv)
{
size_t i_len, o_len;
size_t retval;
@@ -248,6 +248,10 @@ _PUBLIC_ ssize_t convert_string_convenience(struct smb_iconv_convenience *ic,
char* outbuf = (char*)dest;
smb_iconv_t descriptor;
+ if (allow_badcharcnv) {
+ return -1;
+ }
+
if (srclen == (size_t)-1)
srclen = strlen(inbuf)+1;
@@ -305,10 +309,13 @@ _PUBLIC_ ssize_t convert_string_talloc_convenience(TALLOC_CTX *ctx,
struct smb_iconv_convenience *ic,
charset_t from, charset_t to,
void const *src, size_t srclen,
- void **dest)
+ void **dest, bool allow_badcharcnv)
{
smb_iconv_t descriptor;
+ if (allow_badcharcnv)
+ return (size_t)-1;
+
*dest = NULL;
if (src == NULL || srclen == (size_t)-1 || srclen == 0)
diff --git a/lib/util/charset/charset.h b/lib/util/charset/charset.h
index f027beb8db..3acdde30ad 100644
--- a/lib/util/charset/charset.h
+++ b/lib/util/charset/charset.h
@@ -61,6 +61,7 @@ typedef struct smb_iconv_s {
size_t (*push)(void *cd, const char **inbuf, size_t *inbytesleft,
char **outbuf, size_t *outbytesleft);
void *cd_direct, *cd_pull, *cd_push;
+ char *from_name, *to_name;
} *smb_iconv_t;
/* string manipulation flags */
@@ -117,11 +118,11 @@ ssize_t pull_string(char *dest, const void *src, size_t dest_len, size_t src_len
ssize_t convert_string_talloc(TALLOC_CTX *ctx,
charset_t from, charset_t to,
void const *src, size_t srclen,
- void **dest);
+ void **dest, bool allow_badcharcnv);
-ssize_t convert_string(charset_t from, charset_t to,
+size_t convert_string(charset_t from, charset_t to,
void const *src, size_t srclen,
- void *dest, size_t destlen);
+ void *dest, size_t destlen, bool allow_badcharcnv);
ssize_t iconv_talloc(TALLOC_CTX *mem_ctx,
smb_iconv_t cd,
@@ -150,12 +151,12 @@ struct smb_iconv_convenience *smb_iconv_convenience_init(TALLOC_CTX *mem_ctx,
ssize_t convert_string_convenience(struct smb_iconv_convenience *ic,
charset_t from, charset_t to,
void const *src, size_t srclen,
- void *dest, size_t destlen);
+ void *dest, size_t destlen, bool allow_badcharcnv);
ssize_t convert_string_talloc_convenience(TALLOC_CTX *ctx,
struct smb_iconv_convenience *ic,
charset_t from, charset_t to,
void const *src, size_t srclen,
- void **dest);
+ void **dest, bool allow_badcharcnv);
/* iconv */
smb_iconv_t smb_iconv_open(const char *tocode, const char *fromcode);
int smb_iconv_close(smb_iconv_t cd);
diff --git a/lib/util/charset/tests/iconv.c b/lib/util/charset/tests/iconv.c
index 1facea6136..fbe7b103ab 100644
--- a/lib/util/charset/tests/iconv.c
+++ b/lib/util/charset/tests/iconv.c
@@ -418,7 +418,7 @@ static bool test_string2key(struct torture_context *tctx)
torture_comment(tctx, "converting random buffer\n");
- ret = convert_string_talloc(mem_ctx, CH_UTF16MUNGED, CH_UTF8, (void *)buf, len*2, (void**)&dest);
+ ret = convert_string_talloc(mem_ctx, CH_UTF16MUNGED, CH_UTF8, (void *)buf, len*2, (void**)&dest, false);
if (ret == -1) {
torture_fail(tctx, "Failed to convert random buffer\n");
}
@@ -429,7 +429,7 @@ static bool test_string2key(struct torture_context *tctx)
torture_comment(tctx, "converting fixed buffer to UTF16\n");
- ret = convert_string_talloc(mem_ctx, CH_UTF16MUNGED, CH_UTF16, (void *)le1, 20, (void**)&munged1);
+ ret = convert_string_talloc(mem_ctx, CH_UTF16MUNGED, CH_UTF16, (void *)le1, 20, (void**)&munged1, false);
if (ret == -1) {
torture_fail(tctx, "Failed to convert fixed buffer to UTF16_MUNGED\n");
}
@@ -438,7 +438,7 @@ static bool test_string2key(struct torture_context *tctx)
torture_comment(tctx, "converting fixed buffer to UTF8\n");
- ret = convert_string_talloc(mem_ctx, CH_UTF16MUNGED, CH_UTF8, (void *)le1, 20, (void**)&out1);
+ ret = convert_string_talloc(mem_ctx, CH_UTF16MUNGED, CH_UTF8, (void *)le1, 20, (void**)&out1, false);
if (ret == -1) {
torture_fail(tctx, "Failed to convert fixed buffer to UTF8\n");
}
diff --git a/lib/util/charset/util_unistr.c b/lib/util/charset/util_unistr.c
index 41b9c94cbb..96c987393f 100644
--- a/lib/util/charset/util_unistr.c
+++ b/lib/util/charset/util_unistr.c
@@ -656,7 +656,7 @@ static ssize_t push_ascii(void *dest, const char *src, size_t dest_len, int flag
if (flags & (STR_TERMINATE | STR_TERMINATE_ASCII))
src_len++;
- return convert_string(CH_UNIX, CH_DOS, src, src_len, dest, dest_len);
+ return convert_string(CH_UNIX, CH_DOS, src, src_len, dest, dest_len, false);
}
/**
@@ -672,7 +672,7 @@ _PUBLIC_ ssize_t push_ascii_talloc(TALLOC_CTX *ctx, char **dest, const char *src
{
size_t src_len = strlen(src)+1;
*dest = NULL;
- return convert_string_talloc(ctx, CH_UNIX, CH_DOS, src, src_len, (void **)dest);
+ return convert_string_talloc(ctx, CH_UNIX, CH_DOS, src, src_len, (void **)dest, false);
}
@@ -706,7 +706,7 @@ static ssize_t pull_ascii(char *dest, const void *src, size_t dest_len, size_t s
}
}
- ret = convert_string(CH_DOS, CH_UNIX, src, src_len, dest, dest_len);
+ ret = convert_string(CH_DOS, CH_UNIX, src, src_len, dest, dest_len, false);
if (dest_len)
dest[MIN(ret, dest_len-1)] = 0;
@@ -759,7 +759,7 @@ static ssize_t push_ucs2(void *dest, const char *src, size_t dest_len, int flags
/* ucs2 is always a multiple of 2 bytes */
dest_len &= ~1;
- ret = convert_string(CH_UNIX, CH_UTF16, src, src_len, dest, dest_len);
+ ret = convert_string(CH_UNIX, CH_UTF16, src, src_len, dest, dest_len, false);
if (ret == (size_t)-1) {
return 0;
}
@@ -783,7 +783,7 @@ _PUBLIC_ ssize_t push_ucs2_talloc(TALLOC_CTX *ctx, void **dest, const char *src)
{
size_t src_len = strlen(src)+1;
*dest = NULL;
- return convert_string_talloc(ctx, CH_UNIX, CH_UTF16, src, src_len, dest);
+ return convert_string_talloc(ctx, CH_UNIX, CH_UTF16, src, src_len, dest, false);
}
@@ -799,7 +799,7 @@ _PUBLIC_ ssize_t push_utf8_talloc(TALLOC_CTX *ctx, char **dest, const char *src)
{
size_t src_len = strlen(src)+1;
*dest = NULL;
- return convert_string_talloc(ctx, CH_UNIX, CH_UTF8, src, src_len, (void **)dest);
+ return convert_string_talloc(ctx, CH_UNIX, CH_UTF8, src, src_len, (void **)dest, false);
}
/**
@@ -835,7 +835,7 @@ static size_t pull_ucs2(char *dest, const void *src, size_t dest_len, size_t src
if (src_len != (size_t)-1)
src_len &= ~1;
- ret = convert_string(CH_UTF16, CH_UNIX, src, src_len, dest, dest_len);
+ ret = convert_string(CH_UTF16, CH_UNIX, src, src_len, dest, dest_len, false);
if (dest_len)
dest[MIN(ret, dest_len-1)] = 0;
@@ -854,7 +854,7 @@ _PUBLIC_ ssize_t pull_ascii_talloc(TALLOC_CTX *ctx, char **dest, const char *src
{
size_t src_len = strlen(src)+1;
*dest = NULL;
- return convert_string_talloc(ctx, CH_DOS, CH_UNIX, src, src_len, (void **)dest);
+ return convert_string_talloc(ctx, CH_DOS, CH_UNIX, src, src_len, (void **)dest, false);
}
/**
@@ -869,7 +869,7 @@ _PUBLIC_ ssize_t pull_ucs2_talloc(TALLOC_CTX *ctx, char **dest, const void *src)
{
size_t src_len = utf16_len(src);
*dest = NULL;
- return convert_string_talloc(ctx, CH_UTF16, CH_UNIX, src, src_len, (void **)dest);
+ return convert_string_talloc(ctx, CH_UTF16, CH_UNIX, src, src_len, (void **)dest, false);
}
/**
@@ -884,7 +884,7 @@ _PUBLIC_ ssize_t pull_utf8_talloc(TALLOC_CTX *ctx, char **dest, const char *src)
{
size_t src_len = strlen(src)+1;
*dest = NULL;
- return convert_string_talloc(ctx, CH_UTF8, CH_UNIX, src, src_len, (void **)dest);
+ return convert_string_talloc(ctx, CH_UTF8, CH_UNIX, src, src_len, (void **)dest, false);
}
/**
@@ -950,13 +950,13 @@ _PUBLIC_ ssize_t pull_string(char *dest, const void *src, size_t dest_len, size_
* @param destlen maximal length allowed for string
* @returns the number of bytes occupied in the destination
**/
-_PUBLIC_ ssize_t convert_string(charset_t from, charset_t to,
+_PUBLIC_ size_t convert_string(charset_t from, charset_t to,
void const *src, size_t srclen,
- void *dest, size_t destlen)
+ void *dest, size_t destlen, bool allow_badcharcnv)
{
return convert_string_convenience(get_iconv_convenience(), from, to,
src, srclen,
- dest, destlen);
+ dest, destlen, allow_badcharcnv);
}
/**
@@ -972,10 +972,11 @@ _PUBLIC_ ssize_t convert_string(charset_t from, charset_t to,
_PUBLIC_ ssize_t convert_string_talloc(TALLOC_CTX *ctx,
charset_t from, charset_t to,
void const *src, size_t srclen,
- void **dest)
+ void **dest, bool allow_badcharcnv)
{
return convert_string_talloc_convenience(ctx, get_iconv_convenience(),
- from, to, src, srclen, dest);
+ from, to, src, srclen, dest,
+ allow_badcharcnv);
}