summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2011-03-30 13:08:31 -0700
committerJeremy Allison <jra@samba.org>2011-03-30 23:59:37 +0200
commitc109a70531de72eef30a695248b91704bd0c7c24 (patch)
tree29182afa1ae334e8aee0e71e59aa1a0e5de65f6a
parent9ede19fdccaf09303012208129a093197403ef2c (diff)
downloadsamba-c109a70531de72eef30a695248b91704bd0c7c24.tar.gz
samba-c109a70531de72eef30a695248b91704bd0c7c24.tar.bz2
samba-c109a70531de72eef30a695248b91704bd0c7c24.zip
Fix convert_string() to take a *converted_size arg. and return a bool.
Makes these interfaces much harder to misuse and easier to ensure error checking. Autobuild-User: Jeremy Allison <jra@samba.org> Autobuild-Date: Wed Mar 30 23:59:37 CEST 2011 on sn-devel-104
-rw-r--r--lib/tdr/tdr.c11
-rw-r--r--lib/util/charset/charcnv.c6
-rw-r--r--lib/util/charset/charset.h5
-rw-r--r--lib/util/charset/util_unistr.c68
-rw-r--r--librpc/ndr/ndr_string.c12
-rw-r--r--source3/include/proto.h9
-rw-r--r--source3/lib/charcnv.c74
-rw-r--r--source3/lib/dprintf.c5
-rw-r--r--source3/lib/fstring.c7
-rw-r--r--source3/lib/smbldap.c3
-rw-r--r--source3/smbd/mangle_hash2.c11
-rw-r--r--source3/torture/utable.c19
-rw-r--r--source3/web/cgi.c13
-rw-r--r--source4/torture/basic/utable.c18
14 files changed, 153 insertions, 108 deletions
diff --git a/lib/tdr/tdr.c b/lib/tdr/tdr.c
index 8ce238bf8b..616cc987a9 100644
--- a/lib/tdr/tdr.c
+++ b/lib/tdr/tdr.c
@@ -174,7 +174,8 @@ NTSTATUS tdr_pull_charset(struct tdr_pull *tdr, TALLOC_CTX *ctx, const char **v,
NTSTATUS tdr_push_charset(struct tdr_push *tdr, const char **v, uint32_t length, uint32_t el_size, charset_t chset)
{
- size_t ret, required;
+ size_t required, size = 0;
+ bool ret;
if (length == -1) {
length = strlen(*v) + 1; /* Extra element for null character */
@@ -183,14 +184,14 @@ NTSTATUS tdr_push_charset(struct tdr_push *tdr, const char **v, uint32_t length,
required = el_size * length;
TDR_PUSH_NEED_BYTES(tdr, required);
- ret = convert_string(CH_UNIX, chset, *v, strlen(*v), tdr->data.data+tdr->data.length, required);
- if (ret == -1) {
+ ret = convert_string(CH_UNIX, chset, *v, strlen(*v), tdr->data.data+tdr->data.length, required, &size);
+ if (ret == false) {
return NT_STATUS_INVALID_PARAMETER;
}
/* Make sure the remaining part of the string is filled with zeroes */
- if (ret < required) {
- memset(tdr->data.data+tdr->data.length+ret, 0, required-ret);
+ if (size < required) {
+ memset(tdr->data.data+tdr->data.length+size, 0, required-size);
}
tdr->data.length += required;
diff --git a/lib/util/charset/charcnv.c b/lib/util/charset/charcnv.c
index 3b7dbb3074..cefc788f79 100644
--- a/lib/util/charset/charcnv.c
+++ b/lib/util/charset/charcnv.c
@@ -184,12 +184,12 @@ _PUBLIC_ bool convert_string_handle(struct smb_iconv_handle *ic,
case E2BIG:
reason="No more room";
if (from == CH_UNIX) {
- DEBUG(0,("E2BIG: convert_string(%s,%s): srclen=%d destlen=%d - '%s'\n",
+ DEBUG(0,("E2BIG: convert_string_handle(%s,%s): srclen=%d destlen=%d - '%s'\n",
charset_name(ic, from), charset_name(ic, to),
(int)srclen, (int)destlen,
(const char *)src));
} else {
- DEBUG(0,("E2BIG: convert_string(%s,%s): srclen=%d destlen=%d\n",
+ DEBUG(0,("E2BIG: convert_string_handle(%s,%s): srclen=%d destlen=%d\n",
charset_name(ic, from), charset_name(ic, to),
(int)srclen, (int)destlen));
}
@@ -233,7 +233,7 @@ _PUBLIC_ bool convert_string_talloc_handle(TALLOC_CTX *ctx,
if (descriptor == (smb_iconv_t)-1 || descriptor == (smb_iconv_t)0) {
/* conversion not supported, return -1*/
- DEBUG(3, ("convert_string_talloc: conversion from %s to %s not supported!\n",
+ DEBUG(3, ("convert_string_talloc_handle: conversion from %s to %s not supported!\n",
charset_name(ic, from),
charset_name(ic, to)));
return false;
diff --git a/lib/util/charset/charset.h b/lib/util/charset/charset.h
index b17ceabd83..7374d6e2ec 100644
--- a/lib/util/charset/charset.h
+++ b/lib/util/charset/charset.h
@@ -150,9 +150,10 @@ bool convert_string_talloc(TALLOC_CTX *ctx,
void const *src, size_t srclen,
void *dest, size_t *converted_size);
-size_t convert_string(charset_t from, charset_t to,
+bool convert_string(charset_t from, charset_t to,
void const *src, size_t srclen,
- void *dest, size_t destlen);
+ void *dest, size_t destlen,
+ size_t *converted_size);
ssize_t iconv_talloc(TALLOC_CTX *mem_ctx,
smb_iconv_t cd,
diff --git a/lib/util/charset/util_unistr.c b/lib/util/charset/util_unistr.c
index f761613ba8..284863a71c 100644
--- a/lib/util/charset/util_unistr.c
+++ b/lib/util/charset/util_unistr.c
@@ -339,7 +339,8 @@ _PUBLIC_ size_t count_chars_m(const char *s, char c)
/**
* Copy a string from a char* unix src to a dos codepage string destination.
*
- * @return the number of bytes occupied by the string in the destination.
+ * @converted_size the number of bytes occupied by the string in the destination.
+ * @return bool true if success.
*
* @param flags can include
* <dl>
@@ -350,17 +351,17 @@ _PUBLIC_ size_t count_chars_m(const char *s, char c)
* @param dest_len the maximum length in bytes allowed in the
* destination. If @p dest_len is -1 then no maximum is used.
**/
-static ssize_t push_ascii(void *dest, const char *src, size_t dest_len, int flags)
+static bool push_ascii(void *dest, const char *src, size_t dest_len, int flags, size_t *converted_size)
{
size_t src_len;
- ssize_t ret;
+ bool ret;
if (flags & STR_UPPER) {
char *tmpbuf = strupper_talloc(NULL, src);
if (tmpbuf == NULL) {
- return -1;
+ return false;
}
- ret = push_ascii(dest, tmpbuf, dest_len, flags & ~STR_UPPER);
+ ret = push_ascii(dest, tmpbuf, dest_len, flags & ~STR_UPPER, converted_size);
talloc_free(tmpbuf);
return ret;
}
@@ -370,7 +371,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, converted_size);
}
/**
@@ -407,7 +408,7 @@ _PUBLIC_ bool push_ascii_talloc(TALLOC_CTX *ctx, char **dest, const char *src, s
**/
static ssize_t pull_ascii(char *dest, const void *src, size_t dest_len, size_t src_len, int flags)
{
- size_t ret;
+ size_t size = 0;
if (flags & (STR_TERMINATE | STR_TERMINATE_ASCII)) {
if (src_len == (size_t)-1) {
@@ -420,10 +421,11 @@ 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);
+ /* We're ignoring the return here.. */
+ (void)convert_string(CH_DOS, CH_UNIX, src, src_len, dest, dest_len, &size);
if (dest_len)
- dest[MIN(ret, dest_len-1)] = 0;
+ dest[MIN(size, dest_len-1)] = 0;
return src_len;
}
@@ -448,16 +450,18 @@ static ssize_t push_ucs2(void *dest, const char *src, size_t dest_len, int flags
{
size_t len=0;
size_t src_len = strlen(src);
- size_t ret;
+ size_t size = 0;
+ bool ret;
if (flags & STR_UPPER) {
char *tmpbuf = strupper_talloc(NULL, src);
+ ssize_t retval;
if (tmpbuf == NULL) {
return -1;
}
- ret = push_ucs2(dest, tmpbuf, dest_len, flags & ~STR_UPPER);
+ retval = push_ucs2(dest, tmpbuf, dest_len, flags & ~STR_UPPER);
talloc_free(tmpbuf);
- return ret;
+ return retval;
}
if (flags & STR_TERMINATE)
@@ -473,14 +477,14 @@ 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);
- if (ret == (size_t)-1) {
+ ret = convert_string(CH_UNIX, CH_UTF16, src, src_len, dest, dest_len, &size);
+ if (ret == false) {
return 0;
}
- len += ret;
+ len += size;
- return len;
+ return (ssize_t)len;
}
@@ -529,7 +533,7 @@ _PUBLIC_ bool push_utf8_talloc(TALLOC_CTX *ctx, char **dest, const char *src, si
static size_t pull_ucs2(char *dest, const void *src, size_t dest_len, size_t src_len, int flags)
{
- size_t ret;
+ size_t size = 0;
if (ucs2_align(NULL, src, flags)) {
src = (const void *)((const char *)src + 1);
@@ -548,10 +552,11 @@ static size_t pull_ucs2(char *dest, const void *src, size_t dest_len, size_t src
/* ucs2 is always a multiple of 2 bytes */
if (src_len != (size_t)-1)
src_len &= ~1;
-
- ret = convert_string(CH_UTF16, CH_UNIX, src, src_len, dest, dest_len);
+
+ /* We're ignoring the return here.. */
+ (void)convert_string(CH_UTF16, CH_UNIX, src, src_len, dest, dest_len, &size);
if (dest_len)
- dest[MIN(ret, dest_len-1)] = 0;
+ dest[MIN(size, dest_len-1)] = 0;
return src_len;
}
@@ -618,7 +623,12 @@ _PUBLIC_ bool pull_utf8_talloc(TALLOC_CTX *ctx, char **dest, const char *src, si
_PUBLIC_ ssize_t push_string(void *dest, const char *src, size_t dest_len, int flags)
{
if (flags & STR_ASCII) {
- return push_ascii(dest, src, dest_len, flags);
+ size_t size = 0;
+ if (push_ascii(dest, src, dest_len, flags, &size)) {
+ return (ssize_t)size;
+ } else {
+ return (ssize_t)-1;
+ }
} else if (flags & STR_UNICODE) {
return push_ucs2(dest, src, dest_len, flags);
} else {
@@ -662,18 +672,18 @@ _PUBLIC_ ssize_t pull_string(char *dest, const void *src, size_t dest_len, size_
* @param srclen length of the source string in bytes
* @param dest pointer to destination string (multibyte or singlebyte)
* @param destlen maximal length allowed for string
- * @returns the number of bytes occupied in the destination
+ * @param converted_size the number of bytes occupied in the destination
+ *
+ * @returns true on success, false on fail.
**/
-_PUBLIC_ size_t convert_string(charset_t from, charset_t to,
+_PUBLIC_ bool convert_string(charset_t from, charset_t to,
void const *src, size_t srclen,
- void *dest, size_t destlen)
+ void *dest, size_t destlen,
+ size_t *converted_size)
{
- size_t ret;
- if (!convert_string_handle(get_iconv_handle(), from, to,
+ return convert_string_handle(get_iconv_handle(), from, to,
src, srclen,
- dest, destlen, &ret))
- return -1;
- return ret;
+ dest, destlen, converted_size);
}
/**
diff --git a/librpc/ndr/ndr_string.c b/librpc/ndr/ndr_string.c
index 9cc26dacc5..6e20333f04 100644
--- a/librpc/ndr/ndr_string.c
+++ b/librpc/ndr/ndr_string.c
@@ -696,7 +696,7 @@ _PUBLIC_ enum ndr_err_code ndr_pull_charset(struct ndr_pull *ndr, int ndr_flags,
_PUBLIC_ enum ndr_err_code ndr_push_charset(struct ndr_push *ndr, int ndr_flags, const char *var, uint32_t length, uint8_t byte_mul, charset_t chset)
{
- ssize_t ret, required;
+ ssize_t required;
if (NDR_BE(ndr) && chset == CH_UTF16) {
chset = CH_UTF16BE;
@@ -707,17 +707,17 @@ _PUBLIC_ enum ndr_err_code ndr_push_charset(struct ndr_push *ndr, int ndr_flags,
NDR_PUSH_NEED_BYTES(ndr, required);
if (required) {
- ret = convert_string(CH_UNIX, chset,
+ size_t size = 0;
+ if (!convert_string(CH_UNIX, chset,
var, strlen(var),
- ndr->data+ndr->offset, required);
- if (ret == -1) {
+ ndr->data+ndr->offset, required, &size)) {
return ndr_push_error(ndr, NDR_ERR_CHARCNV,
"Bad character conversion");
}
/* Make sure the remaining part of the string is filled with zeroes */
- if (ret < required) {
- memset(ndr->data+ndr->offset+ret, 0, required-ret);
+ if (size < required) {
+ memset(ndr->data+ndr->offset+size, 0, required-size);
}
}
diff --git a/source3/include/proto.h b/source3/include/proto.h
index 94c924591f..a85b2f9e60 100644
--- a/source3/include/proto.h
+++ b/source3/include/proto.h
@@ -74,17 +74,18 @@ int bitmap_find(struct bitmap *bm, unsigned ofs);
void gfree_charcnv(void);
void init_iconv(void);
-size_t convert_string(charset_t from, charset_t to,
+bool convert_string(charset_t from, charset_t to,
void const *src, size_t srclen,
- void *dest, size_t destlen);
+ void *dest, size_t destlen,
+ size_t *converted_size);
bool convert_string_error(charset_t from, charset_t to,
void const *src, size_t srclen,
void *dest, size_t destlen,
size_t *converted_size);
-size_t unix_strupper(const char *src, size_t srclen, char *dest, size_t destlen);
+bool unix_strupper(const char *src, size_t srclen, char *dest, size_t destlen);
char *talloc_strdup_upper(TALLOC_CTX *ctx, const char *s);
char *strupper_talloc(TALLOC_CTX *ctx, const char *s);
-size_t unix_strlower(const char *src, size_t srclen, char *dest, size_t destlen);
+bool unix_strlower(const char *src, size_t srclen, char *dest, size_t destlen);
char *talloc_strdup_lower(TALLOC_CTX *ctx, const char *s);
char *strlower_talloc(TALLOC_CTX *ctx, const char *s);
size_t ucs2_align(const void *base_ptr, const void *p, int flags);
diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c
index 76fa968457..3fd574b985 100644
--- a/source3/lib/charcnv.c
+++ b/source3/lib/charcnv.c
@@ -299,12 +299,12 @@ bool convert_string_error(charset_t from, charset_t to,
return convert_string_internal(from, to, src, srclen, dest, destlen, converted_size);
}
-size_t convert_string(charset_t from, charset_t to,
+bool convert_string(charset_t from, charset_t to,
void const *src, size_t srclen,
- void *dest, size_t destlen)
+ void *dest, size_t destlen,
+ size_t *converted_size)
{
- size_t converted_size;
- bool ret = convert_string_error(from, to, src, srclen, dest, destlen, &converted_size);
+ bool ret = convert_string_error(from, to, src, srclen, dest, destlen, converted_size);
if(ret==false) {
const char *reason="unknown error";
@@ -344,7 +344,7 @@ size_t convert_string(charset_t from, charset_t to,
}
/* smb_panic(reason); */
}
- return ret ? converted_size : (size_t)-1;
+ return ret;
}
@@ -500,10 +500,11 @@ bool convert_string_talloc(TALLOC_CTX *ctx, charset_t from, charset_t to,
return true;
}
-size_t unix_strupper(const char *src, size_t srclen, char *dest, size_t destlen)
+bool unix_strupper(const char *src, size_t srclen, char *dest, size_t destlen)
{
size_t size;
smb_ucs2_t *buffer;
+ bool ret;
if (!push_ucs2_talloc(talloc_tos(), &buffer, src, &size)) {
return (size_t)-1;
@@ -514,9 +515,9 @@ size_t unix_strupper(const char *src, size_t srclen, char *dest, size_t destlen)
return srclen;
}
- size = convert_string(CH_UTF16LE, CH_UNIX, buffer, size, dest, destlen);
+ ret = convert_string(CH_UTF16LE, CH_UNIX, buffer, size, dest, destlen, &size);
TALLOC_FREE(buffer);
- return size;
+ return ret;
}
/**
@@ -584,10 +585,11 @@ char *strupper_talloc(TALLOC_CTX *ctx, const char *s) {
}
-size_t unix_strlower(const char *src, size_t srclen, char *dest, size_t destlen)
+bool unix_strlower(const char *src, size_t srclen, char *dest, size_t destlen)
{
size_t size;
smb_ucs2_t *buffer = NULL;
+ bool ret;
if (!convert_string_talloc(talloc_tos(), CH_UNIX, CH_UTF16LE, src, srclen,
(void **)(void *)&buffer, &size))
@@ -598,9 +600,9 @@ size_t unix_strlower(const char *src, size_t srclen, char *dest, size_t destlen)
TALLOC_FREE(buffer);
return srclen;
}
- size = convert_string(CH_UTF16LE, CH_UNIX, buffer, size, dest, destlen);
+ ret = convert_string(CH_UTF16LE, CH_UNIX, buffer, size, dest, destlen, &size);
TALLOC_FREE(buffer);
- return size;
+ return ret;
}
@@ -656,7 +658,8 @@ size_t push_ascii(void *dest, const char *src, size_t dest_len, int flags)
{
size_t src_len = strlen(src);
char *tmpbuf = NULL;
- size_t ret;
+ size_t size;
+ bool ret;
/* No longer allow a length of -1. */
if (dest_len == (size_t)-1) {
@@ -676,14 +679,14 @@ size_t push_ascii(void *dest, const char *src, size_t dest_len, int flags)
src_len++;
}
- ret = convert_string(CH_UNIX, CH_DOS, src, src_len, dest, dest_len);
- if (ret == (size_t)-1 &&
+ ret = convert_string(CH_UNIX, CH_DOS, src, src_len, dest, dest_len, &size);
+ if (ret == false &&
(flags & (STR_TERMINATE | STR_TERMINATE_ASCII))
&& dest_len > 0) {
((char *)dest)[0] = '\0';
}
SAFE_FREE(tmpbuf);
- return ret;
+ return ret ? size : (size_t)-1;
}
/********************************************************************
@@ -716,7 +719,8 @@ bool push_ascii_talloc(TALLOC_CTX *mem_ctx, char **dest, const char *src, size_t
**/
size_t pull_ascii(char *dest, const void *src, size_t dest_len, size_t src_len, int flags)
{
- size_t ret;
+ bool ret;
+ size_t size = 0;
if (dest_len == (size_t)-1) {
/* No longer allow dest_len of -1. */
@@ -734,16 +738,16 @@ 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);
- if (ret == (size_t)-1) {
- ret = 0;
+ ret = convert_string(CH_DOS, CH_UNIX, src, src_len, dest, dest_len, &size);
+ if (ret == false) {
+ size = 0;
dest_len = 0;
}
- if (dest_len && ret) {
+ if (dest_len && size) {
/* Did we already process the terminating zero ? */
- if (dest[MIN(ret-1, dest_len-1)] != 0) {
- dest[MIN(ret, dest_len-1)] = 0;
+ if (dest[MIN(size-1, dest_len-1)] != 0) {
+ dest[MIN(size, dest_len-1)] = 0;
}
} else {
dest[0] = 0;
@@ -858,7 +862,8 @@ size_t push_ucs2(const void *base_ptr, void *dest, const char *src, size_t dest_
{
size_t len=0;
size_t src_len;
- size_t ret;
+ size_t size = 0;
+ bool ret;
if (dest_len == (size_t)-1) {
/* No longer allow dest_len of -1. */
@@ -881,8 +886,8 @@ size_t push_ucs2(const void *base_ptr, void *dest, const char *src, size_t dest_
/* ucs2 is always a multiple of 2 bytes */
dest_len &= ~1;
- ret = convert_string(CH_UNIX, CH_UTF16LE, src, src_len, dest, dest_len);
- if (ret == (size_t)-1) {
+ ret = convert_string(CH_UNIX, CH_UTF16LE, src, src_len, dest, dest_len, &size);
+ if (ret == false) {
if ((flags & STR_TERMINATE) &&
dest &&
dest_len) {
@@ -891,7 +896,7 @@ size_t push_ucs2(const void *base_ptr, void *dest, const char *src, size_t dest_
return len;
}
- len += ret;
+ len += size;
if (flags & STR_UPPER) {
smb_ucs2_t *dest_ucs2 = (smb_ucs2_t *)dest;
@@ -968,8 +973,9 @@ bool push_utf8_talloc(TALLOC_CTX *ctx, char **dest, const char *src,
size_t pull_ucs2(const void *base_ptr, char *dest, const void *src, size_t dest_len, size_t src_len, int flags)
{
- size_t ret;
+ size_t size = 0;
size_t ucs2_align_len = 0;
+ bool ret;
if (dest_len == (size_t)-1) {
/* No longer allow dest_len of -1. */
@@ -1005,19 +1011,19 @@ size_t pull_ucs2(const void *base_ptr, char *dest, const void *src, size_t dest_
if (src_len != (size_t)-1)
src_len &= ~1;
- ret = convert_string(CH_UTF16LE, CH_UNIX, src, src_len, dest, dest_len);
- if (ret == (size_t)-1) {
- ret = 0;
+ ret = convert_string(CH_UTF16LE, CH_UNIX, src, src_len, dest, dest_len, &size);
+ if (ret == false) {
+ size = 0;
dest_len = 0;
}
if (src_len == (size_t)-1)
- src_len = ret*2;
+ src_len = size*2;
- if (dest_len && ret) {
+ if (dest_len && size) {
/* Did we already process the terminating zero ? */
- if (dest[MIN(ret-1, dest_len-1)] != 0) {
- dest[MIN(ret, dest_len-1)] = 0;
+ if (dest[MIN(size-1, dest_len-1)] != 0) {
+ dest[MIN(size, dest_len-1)] = 0;
}
} else {
dest[0] = 0;
diff --git a/source3/lib/dprintf.c b/source3/lib/dprintf.c
index 97129f8b4a..ad3c79a8d5 100644
--- a/source3/lib/dprintf.c
+++ b/source3/lib/dprintf.c
@@ -35,6 +35,7 @@
{
char *p = NULL, *p2 = NULL;
int ret, maxlen, clen;
+ size_t size = 0;
const char *msgstr;
va_list ap2;
@@ -66,11 +67,11 @@ again:
goto out;
}
- clen = convert_string(CH_UNIX, CH_DISPLAY, p, ret, p2, maxlen);
- if (clen == -1) {
+ if (!convert_string(CH_UNIX, CH_DISPLAY, p, ret, p2, maxlen, &size)) {
ret = -1;
goto out;
}
+ clen = size;
if (clen >= maxlen) {
/* it didn't fit - try a larger buffer */
diff --git a/source3/lib/fstring.c b/source3/lib/fstring.c
index 50b0765f92..b0a30b52cc 100644
--- a/source3/lib/fstring.c
+++ b/source3/lib/fstring.c
@@ -75,7 +75,8 @@ size_t pull_ascii_nstring(char *dest, size_t dest_len, const void *src)
static size_t push_utf8(void *dest, const char *src, size_t dest_len, int flags)
{
size_t src_len = 0;
- size_t ret;
+ size_t size = 0;
+ bool ret;
char *tmpbuf = NULL;
if (dest_len == (size_t)-1) {
@@ -97,9 +98,9 @@ static size_t push_utf8(void *dest, const char *src, size_t dest_len, int flags)
src_len++;
}
- ret = convert_string(CH_UNIX, CH_UTF8, src, src_len, dest, dest_len);
+ ret = convert_string(CH_UNIX, CH_UTF8, src, src_len, dest, dest_len, &size);
TALLOC_FREE(tmpbuf);
- return ret;
+ return ret ? size : (size_t)-1;
}
size_t push_utf8_fstring(void *dest, const char *src)
diff --git a/source3/lib/smbldap.c b/source3/lib/smbldap.c
index c094fbe255..207f435d28 100644
--- a/source3/lib/smbldap.c
+++ b/source3/lib/smbldap.c
@@ -264,6 +264,7 @@ ATTRIB_MAP_ENTRY sidmap_attr_list[] = {
int max_len)
{
char **values;
+ size_t size = 0;
if ( !attribute )
return False;
@@ -276,7 +277,7 @@ ATTRIB_MAP_ENTRY sidmap_attr_list[] = {
return False;
}
- if (convert_string(CH_UTF8, CH_UNIX,values[0], -1, value, max_len) == (size_t)-1) {
+ if (!convert_string(CH_UTF8, CH_UNIX,values[0], -1, value, max_len, &size)) {
DEBUG(1, ("smbldap_get_single_attribute: string conversion of [%s] = [%s] failed!\n",
attribute, values[0]));
ldap_value_free(values);
diff --git a/source3/smbd/mangle_hash2.c b/source3/smbd/mangle_hash2.c
index 367c21688a..a39bb895c2 100644
--- a/source3/smbd/mangle_hash2.c
+++ b/source3/smbd/mangle_hash2.c
@@ -627,6 +627,7 @@ static bool is_legal_name(const char *name)
if (((unsigned int)name[0]) > 128 && (name[1] != 0)) {
/* Possible start of mb character. */
char mbc[2];
+ size_t size = 0;
/*
* Note that if CH_UNIX is utf8 a string may be 3
* bytes, but this is ok as mb utf8 characters don't
@@ -634,10 +635,12 @@ static bool is_legal_name(const char *name)
* for mb UNIX asian characters like Japanese (SJIS) here.
* JRA.
*/
- if (convert_string(CH_UNIX, CH_UTF16LE, name, 2, mbc, 2) == 2) {
- /* Was a good mb string. */
- name += 2;
- continue;
+ if (convert_string(CH_UNIX, CH_UTF16LE, name, 2, mbc, 2, &size)) {
+ if (size == 2) {
+ /* Was a good mb string. */
+ name += 2;
+ continue;
+ }
}
}
diff --git a/source3/torture/utable.c b/source3/torture/utable.c
index 3ddb468834..e7ee00a8a3 100644
--- a/source3/torture/utable.c
+++ b/source3/torture/utable.c
@@ -45,14 +45,19 @@ bool torture_utable(int dummy)
cli_unlink(cli, "\\utable\\*", aSYSTEM | aHIDDEN);
for (c=1; c < 0x10000; c++) {
+ size_t size = 0;
char *p;
SSVAL(&c2, 0, c);
fstrcpy(fname, "\\utable\\x");
p = fname+strlen(fname);
- len = convert_string(CH_UTF16LE, CH_UNIX,
+ if (!convert_string(CH_UTF16LE, CH_UNIX,
&c2, 2,
- p, sizeof(fname)-strlen(fname));
+ p, sizeof(fname)-strlen(fname),&size)) {
+ d_printf("convert_string %s failed !\n", fname);
+ continue;
+ }
+ len = size;
p[len] = 0;
fstrcat(fname,"_a_long_extension");
@@ -106,15 +111,19 @@ static char *form_name(int c)
static fstring fname;
smb_ucs2_t c2;
char *p;
- int len;
+ size_t len = 0;
fstrcpy(fname, "\\utable\\");
p = fname+strlen(fname);
SSVAL(&c2, 0, c);
- len = convert_string(CH_UTF16LE, CH_UNIX,
+ if (!convert_string(CH_UTF16LE, CH_UNIX,
&c2, 2,
- p, sizeof(fname)-strlen(fname));
+ p, sizeof(fname)-strlen(fname), &len)) {
+ d_printf("form_name: convert string %s failed\n",
+ fname);
+ return NULL;
+ }
p[len] = 0;
return fname;
}
diff --git a/source3/web/cgi.c b/source3/web/cgi.c
index 94590a28de..fa2304016e 100644
--- a/source3/web/cgi.c
+++ b/source3/web/cgi.c
@@ -345,6 +345,7 @@ static bool cgi_handle_authorization(char *line)
struct passwd *pass = NULL;
const char *rhost;
char addr[INET6_ADDRSTRLEN];
+ size_t size = 0;
if (!strnequal(line,"Basic ", 6)) {
goto err;
@@ -361,13 +362,17 @@ static bool cgi_handle_authorization(char *line)
}
*p = 0;
- convert_string(CH_UTF8, CH_UNIX,
+ if (!convert_string(CH_UTF8, CH_UNIX,
line, -1,
- user, sizeof(user));
+ user, sizeof(user), &size)) {
+ goto err;
+ }
- convert_string(CH_UTF8, CH_UNIX,
+ if (!convert_string(CH_UTF8, CH_UNIX,
p+1, -1,
- user_pass, sizeof(user_pass));
+ user_pass, sizeof(user_pass), &size)) {
+ goto err;
+ }
/*
* Try and get the user from the UNIX password file.
diff --git a/source4/torture/basic/utable.c b/source4/torture/basic/utable.c
index eaa3f39e9c..d5b808244d 100644
--- a/source4/torture/basic/utable.c
+++ b/source4/torture/basic/utable.c
@@ -50,9 +50,15 @@ bool torture_utable(struct torture_context *tctx,
SSVAL(c2, 0, c);
strncpy(fname, "\\utable\\x", sizeof(fname)-1);
p = fname+strlen(fname);
- len = convert_string(CH_UTF16, CH_UNIX,
+ len = 0;
+ if (!convert_string(CH_UTF16, CH_UNIX,
c2, 2,
- p, sizeof(fname)-strlen(fname));
+ p, sizeof(fname)-strlen(fname), &len)) {
+ torture_comment(tctx, "convert_string failed [%s]\n",
+ fname);
+ continue;
+ }
+
p[len] = 0;
strncat(fname,"_a_long_extension",sizeof(fname)-1);
@@ -103,17 +109,17 @@ static char *form_name(int c)
static char fname[256];
uint8_t c2[4];
char *p;
- size_t len;
+ size_t len = 0;
strncpy(fname, "\\utable\\", sizeof(fname)-1);
p = fname+strlen(fname);
SSVAL(c2, 0, c);
- len = convert_string(CH_UTF16, CH_UNIX,
+ if (!convert_string(CH_UTF16, CH_UNIX,
c2, 2,
- p, sizeof(fname)-strlen(fname));
- if (len == -1)
+ p, sizeof(fname)-strlen(fname), &len)) {
return NULL;
+ }
p[len] = 0;
return fname;
}