diff options
author | Tim Prouty <tim.prouty@isilon.com> | 2008-04-29 14:36:24 -0700 |
---|---|---|
committer | Volker Lendecke <vl@samba.org> | 2008-05-20 22:40:13 +0200 |
commit | fb37f156009611af0dd454a0fb0829a09cd638ac (patch) | |
tree | e97403a13dd39b7ef485d36c6c7856045e6e4bf3 | |
parent | 6ed27edbcd3ba1893636a8072c8d7a621437daf7 (diff) | |
download | samba-fb37f156009611af0dd454a0fb0829a09cd638ac.tar.gz samba-fb37f156009611af0dd454a0fb0829a09cd638ac.tar.bz2 samba-fb37f156009611af0dd454a0fb0829a09cd638ac.zip |
Cleanup size_t return values in callers of convert_string_allocate
This patch is the second iteration of an inside-out conversion to cleanup
functions in charcnv.c returning size_t == -1 to indicate failure.
(This used to be commit 6b189dabc562d86dcaa685419d0cb6ea276f100d)
29 files changed, 537 insertions, 400 deletions
diff --git a/source3/include/proto.h b/source3/include/proto.h index bf6328d5fd..a0354a3920 100644 --- a/source3/include/proto.h +++ b/source3/include/proto.h @@ -366,9 +366,9 @@ size_t convert_string(charset_t from, charset_t to, bool convert_string_allocate(TALLOC_CTX *ctx, charset_t from, charset_t to, void const *src, size_t srclen, void *dst, size_t *converted_size, bool allow_bad_conv); -size_t convert_string_talloc(TALLOC_CTX *ctx, charset_t from, charset_t to, - void const *src, size_t srclen, void *dst, - bool allow_bad_conv); +bool convert_string_talloc(TALLOC_CTX *ctx, charset_t from, charset_t to, + void const *src, size_t srclen, void *dst, + size_t *converted_size, bool allow_bad_conv); size_t unix_strupper(const char *src, size_t srclen, char *dest, size_t destlen); char *strdup_upper(const char *s); char *talloc_strdup_upper(TALLOC_CTX *ctx, const char *s); @@ -379,16 +379,17 @@ size_t ucs2_align(const void *base_ptr, const void *p, int flags); size_t push_ascii(void *dest, const char *src, size_t dest_len, int flags); size_t push_ascii_fstring(void *dest, const char *src); size_t push_ascii_nstring(void *dest, const char *src); -size_t push_ascii_allocate(char **dest, const char *src); +bool push_ascii_allocate(char **dest, const char *src, size_t *converted_size); size_t pull_ascii(char *dest, const void *src, size_t dest_len, size_t src_len, int flags); size_t pull_ascii_fstring(char *dest, const void *src); size_t pull_ascii_nstring(char *dest, size_t dest_len, const void *src); size_t push_ucs2(const void *base_ptr, void *dest, const char *src, size_t dest_len, int flags); -size_t push_ucs2_talloc(TALLOC_CTX *ctx, smb_ucs2_t **dest, const char *src); -size_t push_ucs2_allocate(smb_ucs2_t **dest, const char *src); +bool push_ucs2_allocate(smb_ucs2_t **dest, const char *src, + size_t *converted_size); size_t push_utf8_fstring(void *dest, const char *src); -size_t push_utf8_talloc(TALLOC_CTX *ctx, char **dest, const char *src); -size_t push_utf8_allocate(char **dest, const char *src); +bool push_utf8_talloc(TALLOC_CTX *ctx, char **dest, const char *src, + size_t *converted_size); +bool push_utf8_allocate(char **dest, const char *src, size_t *converted_size); 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 pull_ucs2_base_talloc(TALLOC_CTX *ctx, const void *base_ptr, @@ -397,11 +398,17 @@ size_t pull_ucs2_base_talloc(TALLOC_CTX *ctx, size_t src_len, int flags); size_t pull_ucs2_fstring(char *dest, const void *src); -size_t pull_ucs2_talloc(TALLOC_CTX *ctx, char **dest, const smb_ucs2_t *src); -size_t pull_ucs2_allocate(char **dest, const smb_ucs2_t *src); -size_t pull_utf8_talloc(TALLOC_CTX *ctx, char **dest, const char *src); -size_t pull_utf8_allocate(char **dest, const char *src); -size_t pull_ascii_talloc(TALLOC_CTX *ctx, char **dest, const char *src); +bool push_ucs2_talloc(TALLOC_CTX *ctx, smb_ucs2_t **dest, const char *src, + size_t *converted_size); +bool pull_ucs2_allocate(char **dest, const smb_ucs2_t *src, + size_t *converted_size); +bool pull_utf8_talloc(TALLOC_CTX *ctx, char **dest, const char *src, + size_t *converted_size); +bool pull_utf8_allocate(char **dest, const char *src, size_t *converted_size); +bool pull_ucs2_talloc(TALLOC_CTX *ctx, char **dest, const smb_ucs2_t *src, + size_t *converted_size); +bool pull_ascii_talloc(TALLOC_CTX *ctx, char **dest, const char *src, + size_t *converted_size); size_t push_string_fn(const char *function, unsigned int line, const void *base_ptr, uint16 flags2, void *dest, const char *src, diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 81b7238763..b1a5393461 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -515,7 +515,7 @@ size_t convert_string(charset_t from, charset_t to, * true * @note -1 is not accepted for srclen. * - * @return True if new buffer was correctly allocated, and string was + * @return true if new buffer was correctly allocated, and string was * converted. * * Ensure the srclen contains the terminating zero. @@ -749,24 +749,22 @@ bool convert_string_allocate(TALLOC_CTX *ctx, charset_t from, charset_t to, * * @param srclen length of source buffer. * @param dest always set at least to NULL + * @parm converted_size set to the number of bytes occupied by the string in + * the destination on success. * @note -1 is not accepted for srclen. * - * @returns Size in bytes of the converted string; or -1 in case of error. - **/ -size_t convert_string_talloc(TALLOC_CTX *ctx, charset_t from, charset_t to, - void const *src, size_t srclen, void *dst, - bool allow_bad_conv) + * @return true if new buffer was correctly allocated, and string was + * converted. + */ +bool convert_string_talloc(TALLOC_CTX *ctx, charset_t from, charset_t to, + void const *src, size_t srclen, void *dst, + size_t *converted_size, bool allow_bad_conv) { void **dest = (void **)dst; - size_t dest_len; *dest = NULL; - if (!convert_string_allocate(ctx, from, to, src, srclen, dest, - &dest_len, allow_bad_conv)) - return (size_t)-1; - if (*dest == NULL) - return (size_t)-1; - return dest_len; + return convert_string_allocate(ctx, from, to, src, srclen, dest, + converted_size, allow_bad_conv); } size_t unix_strupper(const char *src, size_t srclen, char *dest, size_t destlen) @@ -774,10 +772,10 @@ size_t unix_strupper(const char *src, size_t srclen, char *dest, size_t destlen) size_t size; smb_ucs2_t *buffer; - size = push_ucs2_allocate(&buffer, src); - if (size == (size_t)-1) { + if (!push_ucs2_allocate(&buffer, src, &size)) { return (size_t)-1; } + if (!strupper_w(buffer) && (dest == src)) { free(buffer); return srclen; @@ -816,20 +814,25 @@ char *strdup_upper(const char *s) if (*p) { /* MB case. */ - size_t size, size2; + size_t converted_size, converted_size2; smb_ucs2_t *buffer = NULL; SAFE_FREE(out_buffer); if (!convert_string_allocate(NULL, CH_UNIX, CH_UTF16LE, s, - strlen(s) + 1, (void **)(void *)&buffer, &size, - True)) { + strlen(s) + 1, + (void **)(void *)&buffer, + &converted_size, True)) + { return NULL; } strupper_w(buffer); if (!convert_string_allocate(NULL, CH_UTF16LE, CH_UNIX, buffer, - size, (void **)(void *)&out_buffer, &size2, True)) { + converted_size, + (void **)(void *)&out_buffer, + &converted_size2, True)) + { TALLOC_FREE(buffer); return NULL; } @@ -871,36 +874,33 @@ char *talloc_strdup_upper(TALLOC_CTX *ctx, const char *s) if (*p) { /* MB case. */ - size_t size; + size_t converted_size, converted_size2; smb_ucs2_t *ubuf = NULL; /* We're not using the ascii buffer above. */ TALLOC_FREE(out_buffer); - size = convert_string_talloc(ctx, CH_UNIX, CH_UTF16LE, - s, strlen(s)+1, - (void *)&ubuf, - True); - if (size == (size_t)-1) { + if (!convert_string_talloc(ctx, CH_UNIX, CH_UTF16LE, s, + strlen(s)+1, (void *)&ubuf, + &converted_size, True)) + { return NULL; } strupper_w(ubuf); - size = convert_string_talloc(ctx, CH_UTF16LE, CH_UNIX, - ubuf, size, - (void *)&out_buffer, - True); + if (!convert_string_talloc(ctx, CH_UTF16LE, CH_UNIX, ubuf, + converted_size, (void *)&out_buffer, + &converted_size2, True)) + { + TALLOC_FREE(ubuf); + return NULL; + } /* Don't need the intermediate buffer * anymore. */ - TALLOC_FREE(ubuf); - - if (size == (size_t)-1) { - return NULL; - } } return out_buffer; @@ -912,7 +912,9 @@ size_t unix_strlower(const char *src, size_t srclen, char *dest, size_t destlen) smb_ucs2_t *buffer = NULL; if (!convert_string_allocate(NULL, CH_UNIX, CH_UTF16LE, src, srclen, - (void **)(void *)&buffer, &size, True)) { + (void **)(void *)&buffer, &size, + True)) + { smb_panic("failed to create UCS2 buffer"); } if (!strlower_w(buffer) && (dest == src)) { @@ -930,49 +932,45 @@ size_t unix_strlower(const char *src, size_t srclen, char *dest, size_t destlen) char *strdup_lower(const char *s) { - size_t size; + size_t converted_size; smb_ucs2_t *buffer = NULL; char *out_buffer; - size = push_ucs2_allocate(&buffer, s); - if (size == -1 || !buffer) { + if (!push_ucs2_allocate(&buffer, s, &converted_size)) { return NULL; } strlower_w(buffer); - size = pull_ucs2_allocate(&out_buffer, buffer); - SAFE_FREE(buffer); - - if (size == (size_t)-1) { + if (!pull_ucs2_allocate(&out_buffer, buffer, &converted_size)) { + SAFE_FREE(buffer); return NULL; } + SAFE_FREE(buffer); + return out_buffer; } char *talloc_strdup_lower(TALLOC_CTX *ctx, const char *s) { - size_t size; + size_t converted_size; smb_ucs2_t *buffer = NULL; char *out_buffer; - size = push_ucs2_talloc(ctx, &buffer, s); - if (size == -1 || !buffer) { - TALLOC_FREE(buffer); + if (!push_ucs2_talloc(ctx, &buffer, s, &converted_size)) { return NULL; } strlower_w(buffer); - size = pull_ucs2_talloc(ctx, &out_buffer, buffer); - TALLOC_FREE(buffer); - - if (size == (size_t)-1) { - TALLOC_FREE(out_buffer); + if (!pull_ucs2_talloc(ctx, &out_buffer, buffer, &converted_size)) { + TALLOC_FREE(buffer); return NULL; } + TALLOC_FREE(buffer); + return out_buffer; } @@ -1049,8 +1047,7 @@ size_t push_ascii_nstring(void *dest, const char *src) smb_ucs2_t *buffer; conv_silent = True; - buffer_len = push_ucs2_allocate(&buffer, src); - if (buffer_len == (size_t)-1) { + if (!push_ucs2_allocate(&buffer, src, &buffer_len)) { smb_panic("failed to create UCS2 buffer"); } @@ -1081,16 +1078,13 @@ size_t push_ascii_nstring(void *dest, const char *src) Push and malloc an ascii string. src and dest null terminated. ********************************************************************/ -size_t push_ascii_allocate(char **dest, const char *src) +bool push_ascii_allocate(char **dest, const char *src, size_t *converted_size) { - size_t dest_len, src_len = strlen(src)+1; + size_t src_len = strlen(src)+1; *dest = NULL; - if (!convert_string_allocate(NULL, CH_UNIX, CH_DOS, src, src_len, - (void **)dest, &dest_len, True)) - return (size_t)-1; - else - return dest_len; + return convert_string_allocate(NULL, CH_UNIX, CH_DOS, src, src_len, + (void **)dest, converted_size, True); } /** @@ -1172,7 +1166,7 @@ static size_t pull_ascii_base_talloc(TALLOC_CTX *ctx, int flags) { char *dest = NULL; - size_t dest_len = 0; + size_t converted_size; #ifdef DEVELOPER /* Ensure we never use the braindead "malloc" varient. */ @@ -1203,13 +1197,15 @@ static size_t pull_ascii_base_talloc(TALLOC_CTX *ctx, } if (!convert_string_allocate(ctx, CH_DOS, CH_UNIX, src, src_len, &dest, - &dest_len, True)) - dest_len = 0; + &converted_size, True)) + { + converted_size = 0; + } - if (dest_len && dest) { + if (converted_size && dest) { /* Did we already process the terminating zero ? */ - if (dest[dest_len-1] != 0) { - dest[dest_len-1] = 0; + if (dest[converted_size - 1] != 0) { + dest[converted_size - 1] = 0; } } else if (dest) { dest[0] = 0; @@ -1311,16 +1307,20 @@ size_t push_ucs2(const void *base_ptr, void *dest, const char *src, size_t dest_ * allocating a buffer using talloc(). * * @param dest always set at least to NULL + * @parm converted_size set to the number of bytes occupied by the string in + * the destination on success. * - * @returns The number of bytes occupied by the string in the destination - * or -1 in case of error. + * @return true if new buffer was correctly allocated, and string was + * converted. **/ -size_t push_ucs2_talloc(TALLOC_CTX *ctx, smb_ucs2_t **dest, const char *src) +bool push_ucs2_talloc(TALLOC_CTX *ctx, smb_ucs2_t **dest, const char *src, + size_t *converted_size) { size_t src_len = strlen(src)+1; *dest = NULL; - return convert_string_talloc(ctx, CH_UNIX, CH_UTF16LE, src, src_len, (void **)dest, True); + return convert_string_talloc(ctx, CH_UNIX, CH_UTF16LE, src, src_len, + (void **)dest, converted_size, True); } @@ -1328,21 +1328,21 @@ size_t push_ucs2_talloc(TALLOC_CTX *ctx, smb_ucs2_t **dest, const char *src) * Copy a string from a unix char* src to a UCS2 destination, allocating a buffer * * @param dest always set at least to NULL + * @parm converted_size set to the number of bytes occupied by the string in + * the destination on success. * - * @returns The number of bytes occupied by the string in the destination - * or -1 in case of error. + * @return true if new buffer was correctly allocated, and string was + * converted. **/ -size_t push_ucs2_allocate(smb_ucs2_t **dest, const char *src) +bool push_ucs2_allocate(smb_ucs2_t **dest, const char *src, + size_t *converted_size) { - size_t dest_len, src_len = strlen(src)+1; + size_t src_len = strlen(src)+1; *dest = NULL; - if (!convert_string_allocate(NULL, CH_UNIX, CH_UTF16LE, src, src_len, - (void **)dest, &dest_len, True)) - return (size_t)-1; - else - return dest_len; + return convert_string_allocate(NULL, CH_UNIX, CH_UTF16LE, src, src_len, + (void **)dest, converted_size, True); } /** @@ -1394,36 +1394,41 @@ size_t push_utf8_fstring(void *dest, const char *src) * Copy a string from a unix char* src to a UTF-8 destination, allocating a buffer using talloc * * @param dest always set at least to NULL + * @parm converted_size set to the number of bytes occupied by the string in + * the destination on success. * - * @returns The number of bytes occupied by the string in the destination + * @return true if new buffer was correctly allocated, and string was + * converted. **/ -size_t push_utf8_talloc(TALLOC_CTX *ctx, char **dest, const char *src) +bool push_utf8_talloc(TALLOC_CTX *ctx, char **dest, const char *src, + size_t *converted_size) { size_t src_len = strlen(src)+1; *dest = NULL; - return convert_string_talloc(ctx, CH_UNIX, CH_UTF8, src, src_len, (void**)dest, True); + return convert_string_talloc(ctx, CH_UNIX, CH_UTF8, src, src_len, + (void**)dest, converted_size, True); } /** * Copy a string from a unix char* src to a UTF-8 destination, allocating a buffer * * @param dest always set at least to NULL + * @parm converted_size set to the number of bytes occupied by the string in + * the destination on success. * - * @returns The number of bytes occupied by the string in the destination + * @return true if new buffer was correctly allocated, and string was + * converted. **/ -size_t push_utf8_allocate(char **dest, const char *src) +bool push_utf8_allocate(char **dest, const char *src, size_t *converted_size) { - size_t dest_len, src_len = strlen(src)+1; + size_t src_len = strlen(src)+1; *dest = NULL; - if (!convert_string_allocate(NULL, CH_UNIX, CH_UTF8, src, src_len, - (void **)dest, &dest_len, True)) - return (size_t)-1; - else - return dest_len; + return convert_string_allocate(NULL, CH_UNIX, CH_UTF8, src, src_len, + (void **)dest, converted_size, True); } /** @@ -1564,14 +1569,8 @@ size_t pull_ucs2_base_talloc(TALLOC_CTX *ctx, src_len &= ~1; } - dest_len = convert_string_talloc(ctx, - CH_UTF16LE, - CH_UNIX, - src, - src_len, - (void *)&dest, - True); - if (dest_len == (size_t)-1) { + if (!convert_string_talloc(ctx, CH_UTF16LE, CH_UNIX, src, src_len, + (void *)&dest, &dest_len, True)) { dest_len = 0; } @@ -1614,83 +1613,103 @@ size_t pull_ucs2_fstring(char *dest, const void *src) * Copy a string from a UCS2 src to a unix char * destination, allocating a buffer using talloc * * @param dest always set at least to NULL + * @parm converted_size set to the number of bytes occupied by the string in + * the destination on success. * - * @returns The number of bytes occupied by the string in the destination + * @return true if new buffer was correctly allocated, and string was + * converted. **/ -size_t pull_ucs2_talloc(TALLOC_CTX *ctx, char **dest, const smb_ucs2_t *src) +bool pull_ucs2_talloc(TALLOC_CTX *ctx, char **dest, const smb_ucs2_t *src, + size_t *converted_size) { size_t src_len = (strlen_w(src)+1) * sizeof(smb_ucs2_t); + *dest = NULL; - return convert_string_talloc(ctx, CH_UTF16LE, CH_UNIX, src, src_len, (void **)dest, True); + return convert_string_talloc(ctx, CH_UTF16LE, CH_UNIX, src, src_len, + (void **)dest, converted_size, True); } /** * Copy a string from a UCS2 src to a unix char * destination, allocating a buffer * * @param dest always set at least to NULL - * - * @returns The number of bytes occupied by the string in the destination + * @parm converted_size set to the number of bytes occupied by the string in + * the destination on success. + * @return true if new buffer was correctly allocated, and string was + * converted. **/ -size_t pull_ucs2_allocate(char **dest, const smb_ucs2_t *src) +bool pull_ucs2_allocate(char **dest, const smb_ucs2_t *src, + size_t *converted_size) { - size_t dest_len, src_len = (strlen_w(src)+1) * sizeof(smb_ucs2_t); + size_t src_len = (strlen_w(src)+1) * sizeof(smb_ucs2_t); + *dest = NULL; - if (!convert_string_allocate(NULL, CH_UTF16LE, CH_UNIX, src, src_len, - (void **)dest, &dest_len, True)) - return (size_t)-1; - else - return dest_len; + return convert_string_allocate(NULL, CH_UTF16LE, CH_UNIX, src, src_len, + (void **)dest, converted_size, True); } /** * Copy a string from a UTF-8 src to a unix char * destination, allocating a buffer using talloc * * @param dest always set at least to NULL + * @parm converted_size set to the number of bytes occupied by the string in + * the destination on success. * - * @returns The number of bytes occupied by the string in the destination + * @return true if new buffer was correctly allocated, and string was + * converted. **/ -size_t pull_utf8_talloc(TALLOC_CTX *ctx, char **dest, const char *src) +bool pull_utf8_talloc(TALLOC_CTX *ctx, char **dest, const char *src, + size_t *converted_size) { size_t src_len = strlen(src)+1; + *dest = NULL; - return convert_string_talloc(ctx, CH_UTF8, CH_UNIX, src, src_len, (void **)dest, True); + return convert_string_talloc(ctx, CH_UTF8, CH_UNIX, src, src_len, + (void **)dest, converted_size, True); } /** * Copy a string from a UTF-8 src to a unix char * destination, allocating a buffer * * @param dest always set at least to NULL + * @parm converted_size set to the number of bytes occupied by the string in + * the destination on success. * - * @returns The number of bytes occupied by the string in the destination + * @return true if new buffer was correctly allocated, and string was + * converted. **/ -size_t pull_utf8_allocate(char **dest, const char *src) +bool pull_utf8_allocate(char **dest, const char *src, size_t *converted_size) { - size_t dest_len, src_len = strlen(src)+1; + size_t src_len = strlen(src)+1; + *dest = NULL; - if (!convert_string_allocate(NULL, CH_UTF8, CH_UNIX, src, src_len, - (void **)dest, &dest_len, True)) - return (size_t)-1; - else - return dest_len; + return convert_string_allocate(NULL, CH_UTF8, CH_UNIX, src, src_len, + (void **)dest, converted_size, True); } /** * Copy a string from a DOS src to a unix char * destination, allocating a buffer using talloc * * @param dest always set at least to NULL + * @parm converted_size set to the number of bytes occupied by the string in + * the destination on success. * - * @returns The number of bytes occupied by the string in the destination + * @return true if new buffer was correctly allocated, and string was + * converted. **/ -size_t pull_ascii_talloc(TALLOC_CTX *ctx, char **dest, const char *src) +bool pull_ascii_talloc(TALLOC_CTX *ctx, char **dest, const char *src, + size_t *converted_size) { size_t src_len = strlen(src)+1; + *dest = NULL; - return convert_string_talloc(ctx, CH_DOS, CH_UNIX, src, src_len, (void **)dest, True); + return convert_string_talloc(ctx, CH_DOS, CH_UNIX, src, src_len, + (void **)dest, converted_size, True); } /** diff --git a/source3/lib/ms_fnmatch.c b/source3/lib/ms_fnmatch.c index 8b69f1c2d2..ca534467fa 100644 --- a/source3/lib/ms_fnmatch.c +++ b/source3/lib/ms_fnmatch.c @@ -154,6 +154,7 @@ int ms_fnmatch(const char *pattern, const char *string, bool translate_pattern, struct max_n *max_n = NULL; struct max_n *max_n_free = NULL; struct max_n one_max_n; + size_t converted_size; if (ISDOTDOT(string)) { string = "."; @@ -169,11 +170,11 @@ int ms_fnmatch(const char *pattern, const char *string, bool translate_pattern, } } - if (push_ucs2_allocate(&p, pattern) == (size_t)-1) { + if (!push_ucs2_allocate(&p, pattern, &converted_size)) { return -1; } - if (push_ucs2_allocate(&s, string) == (size_t)-1) { + if (!push_ucs2_allocate(&s, string, &converted_size)) { SAFE_FREE(p); return -1; } diff --git a/source3/lib/smbldap.c b/source3/lib/smbldap.c index 65a039b119..9fb16f8927 100644 --- a/source3/lib/smbldap.c +++ b/source3/lib/smbldap.c @@ -298,6 +298,7 @@ ATTRIB_MAP_ENTRY sidmap_attr_list[] = { { char **values; char *result; + size_t converted_size; if (attribute == NULL) { return NULL; @@ -317,7 +318,7 @@ ATTRIB_MAP_ENTRY sidmap_attr_list[] = { return NULL; } - if (pull_utf8_talloc(mem_ctx, &result, values[0]) == (size_t)-1) { + if (!pull_utf8_talloc(mem_ctx, &result, values[0], &converted_size)) { DEBUG(10, ("pull_utf8_talloc failed\n")); ldap_value_free(values); return NULL; @@ -430,6 +431,7 @@ ATTRIB_MAP_ENTRY sidmap_attr_list[] = { if (value != NULL) { char *utf8_value = NULL; + size_t converted_size; j = 0; if (mods[i]->mod_values != NULL) { @@ -442,7 +444,7 @@ ATTRIB_MAP_ENTRY sidmap_attr_list[] = { /* notreached. */ } - if (push_utf8_allocate(&utf8_value, value) == (size_t)-1) { + if (!push_utf8_allocate(&utf8_value, value, &converted_size)) { smb_panic("smbldap_set_mod: String conversion failure!"); /* notreached. */ } @@ -1176,6 +1178,7 @@ static int smbldap_search_ext(struct smbldap_state *ldap_state, char *utf8_filter; time_t endtime = time(NULL)+lp_ldap_timeout(); struct timeval timeout; + size_t converted_size; SMB_ASSERT(ldap_state); @@ -1206,7 +1209,7 @@ static int smbldap_search_ext(struct smbldap_state *ldap_state, ZERO_STRUCT(ldap_state->last_rebind); } - if (push_utf8_allocate(&utf8_filter, filter) == (size_t)-1) { + if (!push_utf8_allocate(&utf8_filter, filter, &converted_size)) { return LDAP_NO_MEMORY; } @@ -1372,12 +1375,13 @@ int smbldap_modify(struct smbldap_state *ldap_state, const char *dn, LDAPMod *at int attempts = 0; char *utf8_dn; time_t endtime = time(NULL)+lp_ldap_timeout(); + size_t converted_size; SMB_ASSERT(ldap_state); DEBUG(5,("smbldap_modify: dn => [%s]\n", dn )); - if (push_utf8_allocate(&utf8_dn, dn) == (size_t)-1) { + if (!push_utf8_allocate(&utf8_dn, dn, &converted_size)) { return LDAP_NO_MEMORY; } @@ -1415,12 +1419,13 @@ int smbldap_add(struct smbldap_state *ldap_state, const char *dn, LDAPMod *attrs int attempts = 0; char *utf8_dn; time_t endtime = time(NULL)+lp_ldap_timeout(); + size_t converted_size; SMB_ASSERT(ldap_state); DEBUG(5,("smbldap_add: dn => [%s]\n", dn )); - if (push_utf8_allocate(&utf8_dn, dn) == (size_t)-1) { + if (!push_utf8_allocate(&utf8_dn, dn, &converted_size)) { return LDAP_NO_MEMORY; } @@ -1458,12 +1463,13 @@ int smbldap_delete(struct smbldap_state *ldap_state, const char *dn) int attempts = 0; char *utf8_dn; time_t endtime = time(NULL)+lp_ldap_timeout(); + size_t converted_size; SMB_ASSERT(ldap_state); DEBUG(5,("smbldap_delete: dn => [%s]\n", dn )); - if (push_utf8_allocate(&utf8_dn, dn) == (size_t)-1) { + if (!push_utf8_allocate(&utf8_dn, dn, &converted_size)) { return LDAP_NO_MEMORY; } @@ -1630,14 +1636,16 @@ NTSTATUS smbldap_init(TALLOC_CTX *mem_ctx, struct event_context *event_ctx, char *smbldap_get_dn(LDAP *ld, LDAPMessage *entry) { char *utf8_dn, *unix_dn; + size_t converted_size; utf8_dn = ldap_get_dn(ld, entry); if (!utf8_dn) { DEBUG (5, ("smbldap_get_dn: ldap_get_dn failed\n")); return NULL; } - if (pull_utf8_allocate(&unix_dn, utf8_dn) == (size_t)-1) { - DEBUG (0, ("smbldap_get_dn: String conversion failure utf8 [%s]\n", utf8_dn)); + if (!pull_utf8_allocate(&unix_dn, utf8_dn, &converted_size)) { + DEBUG (0, ("smbldap_get_dn: String conversion failure utf8 " + "[%s]\n", utf8_dn)); return NULL; } ldap_memfree(utf8_dn); @@ -1648,13 +1656,14 @@ char *smbldap_get_dn(LDAP *ld, LDAPMessage *entry) LDAPMessage *entry) { char *utf8_dn, *unix_dn; + size_t converted_size; utf8_dn = ldap_get_dn(ld, entry); if (!utf8_dn) { DEBUG (5, ("smbldap_get_dn: ldap_get_dn failed\n")); return NULL; } - if (pull_utf8_talloc(mem_ctx, &unix_dn, utf8_dn) == (size_t)-1) { + if (!pull_utf8_talloc(mem_ctx, &unix_dn, utf8_dn, &converted_size)) { DEBUG (0, ("smbldap_get_dn: String conversion failure utf8 " "[%s]\n", utf8_dn)); return NULL; diff --git a/source3/lib/util_reg_api.c b/source3/lib/util_reg_api.c index 60031d97d3..8f28e9c282 100644 --- a/source3/lib/util_reg_api.c +++ b/source3/lib/util_reg_api.c @@ -91,16 +91,15 @@ WERROR registry_pull_value(TALLOC_CTX *mem_ctx, goto error; } - value->v.sz.len = convert_string_talloc( - value, CH_UTF16LE, CH_UNIX, tmp, length+2, - &value->v.sz.str, False); - - SAFE_FREE(tmp); - - if (value->v.sz.len == (size_t)-1) { + if (!convert_string_talloc(value, CH_UTF16LE, CH_UNIX, tmp, + length+2, &value->v.sz.str, + &value->v.sz.len, False)) { + SAFE_FREE(tmp); err = WERR_INVALID_PARAM; goto error; } + + SAFE_FREE(tmp); break; } case REG_MULTI_SZ: @@ -143,11 +142,13 @@ WERROR registry_push_value(TALLOC_CTX *mem_ctx, } case REG_SZ: case REG_EXPAND_SZ: { - presult->length = convert_string_talloc( - mem_ctx, CH_UNIX, CH_UTF16LE, value->v.sz.str, - MIN(value->v.sz.len, strlen(value->v.sz.str)+1), - (void *)&(presult->data), False); - if (presult->length == (size_t)-1) { + if (!convert_string_talloc(mem_ctx, CH_UNIX, CH_UTF16LE, + value->v.sz.str, + MIN(value->v.sz.len, + strlen(value->v.sz.str)+1), + (void *)&(presult->data), + &presult->length, False)) + { return WERR_NOMEM; } break; @@ -176,12 +177,13 @@ WERROR registry_push_value(TALLOC_CTX *mem_ctx, /* convert the single strings */ for (count = 0; count < value->v.multi_sz.num_strings; count++) { - string_lengths[count] = convert_string_talloc( - strings, CH_UNIX, CH_UTF16LE, - value->v.multi_sz.strings[count], + if (!convert_string_talloc(strings, CH_UNIX, + CH_UTF16LE, value->v.multi_sz.strings[count], strlen(value->v.multi_sz.strings[count])+1, - (void *)&strings[count], false); - if (string_lengths[count] == (size_t)-1) { + (void *)&strings[count], + &string_lengths[count], false)) + { + TALLOC_FREE(tmp_ctx); return WERR_NOMEM; } diff --git a/source3/lib/util_str.c b/source3/lib/util_str.c index 6310e2464d..5a08f7bc2c 100644 --- a/source3/lib/util_str.c +++ b/source3/lib/util_str.c @@ -208,16 +208,14 @@ int StrCaseCmp(const char *s, const char *t) return +1; } - size = push_ucs2_allocate(&buffer_s, ps); - if (size == (size_t)-1) { + if (!push_ucs2_allocate(&buffer_s, ps, &size)) { return strcmp(ps, pt); /* Not quite the right answer, but finding the right one under this failure case is expensive, and it's pretty close */ } - size = push_ucs2_allocate(&buffer_t, pt); - if (size == (size_t)-1) { + if (!push_ucs2_allocate(&buffer_t, pt, &size)) { SAFE_FREE(buffer_s); return strcmp(ps, pt); /* Not quite the right answer, but finding the right one @@ -271,16 +269,14 @@ int StrnCaseCmp(const char *s, const char *t, size_t len) return 0; } - size = push_ucs2_allocate(&buffer_s, ps); - if (size == (size_t)-1) { + if (!push_ucs2_allocate(&buffer_s, ps, &size)) { return strncmp(ps, pt, len-n); /* Not quite the right answer, but finding the right one under this failure case is expensive, and it's pretty close */ } - size = push_ucs2_allocate(&buffer_t, pt); - if (size == (size_t)-1) { + if (!push_ucs2_allocate(&buffer_t, pt, &size)) { SAFE_FREE(buffer_s); return strncmp(ps, pt, len-n); /* Not quite the right answer, but finding the right one @@ -480,9 +476,9 @@ char *skip_string(const char *base, size_t len, char *buf) size_t str_charnum(const char *s) { - size_t ret; + size_t ret, converted_size; smb_ucs2_t *tmpbuf2 = NULL; - if (push_ucs2_allocate(&tmpbuf2, s) == (size_t)-1) { + if (!push_ucs2_allocate(&tmpbuf2, s, &converted_size)) { return 0; } ret = strlen_w(tmpbuf2); @@ -498,9 +494,9 @@ size_t str_charnum(const char *s) size_t str_ascii_charnum(const char *s) { - size_t ret; + size_t ret, converted_size; char *tmpbuf2 = NULL; - if (push_ascii_allocate(&tmpbuf2, s) == (size_t)-1) { + if (!push_ascii_allocate(&tmpbuf2, s, &converted_size)) { return 0; } ret = strlen(tmpbuf2); @@ -610,8 +606,9 @@ bool strhasupper(const char *s) { smb_ucs2_t *tmp, *p; bool ret; + size_t converted_size; - if (push_ucs2_allocate(&tmp, s) == -1) { + if (!push_ucs2_allocate(&tmp, s, &converted_size)) { return false; } @@ -634,8 +631,9 @@ bool strhaslower(const char *s) { smb_ucs2_t *tmp, *p; bool ret; + size_t converted_size; - if (push_ucs2_allocate(&tmp, s) == -1) { + if (!push_ucs2_allocate(&tmp, s, &converted_size)) { return false; } @@ -659,8 +657,9 @@ size_t count_chars(const char *s,char c) smb_ucs2_t *ptr; int count; smb_ucs2_t *alloc_tmpbuf = NULL; + size_t converted_size; - if (push_ucs2_allocate(&alloc_tmpbuf, s) == (size_t)-1) { + if (!push_ucs2_allocate(&alloc_tmpbuf, s, &converted_size)) { return 0; } @@ -1410,6 +1409,7 @@ char *strchr_m(const char *src, char c) smb_ucs2_t *p; const char *s; char *ret; + size_t converted_size; /* characters below 0x3F are guaranteed to not appear in non-initial position in multi-byte charsets */ @@ -1435,7 +1435,7 @@ char *strchr_m(const char *src, char c) s = src; #endif - if (push_ucs2_allocate(&ws, s)==(size_t)-1) { + if (!push_ucs2_allocate(&ws, s, &converted_size)) { /* Wrong answer, but what can we do... */ return strchr(src, c); } @@ -1445,7 +1445,7 @@ char *strchr_m(const char *src, char c) return NULL; } *p = 0; - if (pull_ucs2_allocate(&s2, ws)==(size_t)-1) { + if (!pull_ucs2_allocate(&s2, ws, &converted_size)) { SAFE_FREE(ws); /* Wrong answer, but what can we do... */ return strchr(src, c); @@ -1504,8 +1504,9 @@ char *strrchr_m(const char *s, char c) char *s2 = NULL; smb_ucs2_t *p; char *ret; + size_t converted_size; - if (push_ucs2_allocate(&ws,s)==(size_t)-1) { + if (!push_ucs2_allocate(&ws, s, &converted_size)) { /* Wrong answer, but what can we do. */ return strrchr(s, c); } @@ -1515,7 +1516,7 @@ char *strrchr_m(const char *s, char c) return NULL; } *p = 0; - if (pull_ucs2_allocate(&s2,ws)==(size_t)-1) { + if (!pull_ucs2_allocate(&s2, ws, &converted_size)) { SAFE_FREE(ws); /* Wrong answer, but what can we do. */ return strrchr(s, c); @@ -1538,8 +1539,9 @@ char *strnrchr_m(const char *s, char c, unsigned int n) char *s2 = NULL; smb_ucs2_t *p; char *ret; + size_t converted_size; - if (push_ucs2_allocate(&ws,s)==(size_t)-1) { + if (!push_ucs2_allocate(&ws, s, &converted_size)) { /* Too hard to try and get right. */ return NULL; } @@ -1549,7 +1551,7 @@ char *strnrchr_m(const char *s, char c, unsigned int n) return NULL; } *p = 0; - if (pull_ucs2_allocate(&s2,ws)==(size_t)-1) { + if (!pull_ucs2_allocate(&s2, ws, &converted_size)) { SAFE_FREE(ws); /* Too hard to try and get right. */ return NULL; @@ -1572,7 +1574,7 @@ char *strstr_m(const char *src, const char *findstr) char *s2; char *retp; - size_t findstr_len = 0; + size_t converted_size, findstr_len = 0; /* for correctness */ if (!findstr[0]) { @@ -1608,12 +1610,12 @@ char *strstr_m(const char *src, const char *findstr) s = src; #endif - if (push_ucs2_allocate(&src_w, src) == (size_t)-1) { + if (!push_ucs2_allocate(&src_w, src, &converted_size)) { DEBUG(0,("strstr_m: src malloc fail\n")); return NULL; } - if (push_ucs2_allocate(&find_w, findstr) == (size_t)-1) { + if (!push_ucs2_allocate(&find_w, findstr, &converted_size)) { SAFE_FREE(src_w); DEBUG(0,("strstr_m: find malloc fail\n")); return NULL; @@ -1628,7 +1630,7 @@ char *strstr_m(const char *src, const char *findstr) } *p = 0; - if (pull_ucs2_allocate(&s2, src_w) == (size_t)-1) { + if (!pull_ucs2_allocate(&s2, src_w, &converted_size)) { SAFE_FREE(src_w); SAFE_FREE(find_w); DEBUG(0,("strstr_m: dest malloc fail\n")); diff --git a/source3/lib/util_unistr.c b/source3/lib/util_unistr.c index 84ee673a67..76235ad041 100644 --- a/source3/lib/util_unistr.c +++ b/source3/lib/util_unistr.c @@ -312,14 +312,12 @@ int rpcstr_pull_unistr2_fstring(char *dest, UNISTR2 *src) char *rpcstr_pull_unistr2_talloc(TALLOC_CTX *ctx, const UNISTR2 *src) { char *dest = NULL; - size_t dest_len = convert_string_talloc(ctx, - CH_UTF16LE, - CH_UNIX, - src->buffer, - src->uni_str_len * 2, - (void *)&dest, - true); - if (dest_len == (size_t)-1) { + size_t dest_len; + + if (!convert_string_talloc(ctx, CH_UTF16LE, CH_UNIX, src->buffer, + src->uni_str_len * 2, (void *)&dest, + &dest_len, true)) + { return NULL; } @@ -364,7 +362,11 @@ int rpcstr_push(void *dest, const char *src, size_t dest_len, int flags) int rpcstr_push_talloc(TALLOC_CTX *ctx, smb_ucs2_t **dest, const char *src) { - return push_ucs2_talloc(ctx, dest, src); + size_t size; + if (push_ucs2_talloc(ctx, dest, src, &size)) + return size; + else + return -1; } /******************************************************************* diff --git a/source3/libads/ldap.c b/source3/libads/ldap.c index 063645febf..37c0c4d0ac 100644 --- a/source3/libads/ldap.c +++ b/source3/libads/ldap.c @@ -593,7 +593,8 @@ static char **ads_push_strvals(TALLOC_CTX *ctx, const char **in_vals) { char **values; int i; - + size_t size; + if (!in_vals) return NULL; for (i=0; in_vals[i]; i++) ; /* count values */ @@ -601,7 +602,7 @@ static char **ads_push_strvals(TALLOC_CTX *ctx, const char **in_vals) if (!values) return NULL; for (i=0; in_vals[i]; i++) { - if (push_utf8_talloc(ctx, &values[i], in_vals[i]) == (size_t) -1) { + if (!push_utf8_talloc(ctx, &values[i], in_vals[i], &size)) { TALLOC_FREE(values); return NULL; } @@ -616,6 +617,7 @@ static char **ads_pull_strvals(TALLOC_CTX *ctx, const char **in_vals) { char **values; int i; + size_t converted_size; if (!in_vals) return NULL; for (i=0; in_vals[i]; i++) @@ -624,7 +626,11 @@ static char **ads_pull_strvals(TALLOC_CTX *ctx, const char **in_vals) if (!values) return NULL; for (i=0; in_vals[i]; i++) { - pull_utf8_talloc(ctx, &values[i], in_vals[i]); + if (!pull_utf8_talloc(ctx, &values[i], in_vals[i], + &converted_size)) { + DEBUG(0,("ads_pull_strvals: pull_utf8_talloc failed: " + "%s", strerror(errno))); + } } return values; } @@ -652,6 +658,7 @@ static ADS_STATUS ads_do_paged_search_args(ADS_STRUCT *ads, { int rc, i, version; char *utf8_expr, *utf8_path, **search_attrs; + size_t converted_size; LDAPControl PagedResults, NoReferrals, ExternalCtrl, *controls[4], **rcontrols; BerElement *cookie_be = NULL; struct berval *cookie_bv= NULL; @@ -669,8 +676,9 @@ static ADS_STATUS ads_do_paged_search_args(ADS_STRUCT *ads, /* 0 means the conversion worked but the result was empty so we only fail if it's -1. In any case, it always at least nulls out the dest */ - if ((push_utf8_talloc(ctx, &utf8_expr, expr) == (size_t)-1) || - (push_utf8_talloc(ctx, &utf8_path, bind_path) == (size_t)-1)) { + if (!push_utf8_talloc(ctx, &utf8_expr, expr, &converted_size) || + !push_utf8_talloc(ctx, &utf8_path, bind_path, &converted_size)) + { rc = LDAP_NO_MEMORY; goto done; } @@ -967,6 +975,7 @@ ADS_STATUS ads_do_search_all_fn(ADS_STRUCT *ads, const char *bind_path, { int rc; char *utf8_expr, *utf8_path, **search_attrs = NULL; + size_t converted_size; TALLOC_CTX *ctx; *res = NULL; @@ -978,8 +987,9 @@ ADS_STATUS ads_do_search_all_fn(ADS_STRUCT *ads, const char *bind_path, /* 0 means the conversion worked but the result was empty so we only fail if it's negative. In any case, it always at least nulls out the dest */ - if ((push_utf8_talloc(ctx, &utf8_expr, expr) == (size_t)-1) || - (push_utf8_talloc(ctx, &utf8_path, bind_path) == (size_t)-1)) { + if (!push_utf8_talloc(ctx, &utf8_expr, expr, &converted_size) || + !push_utf8_talloc(ctx, &utf8_path, bind_path, &converted_size)) + { DEBUG(1,("ads_do_search: push_utf8_talloc() failed!")); rc = LDAP_NO_MEMORY; goto done; @@ -1077,6 +1087,7 @@ void ads_memfree(ADS_STRUCT *ads, void *mem) char *ads_get_dn(ADS_STRUCT *ads, LDAPMessage *msg) { char *utf8_dn, *unix_dn; + size_t converted_size; utf8_dn = ldap_get_dn(ads->ldap.ld, msg); @@ -1085,7 +1096,7 @@ void ads_memfree(ADS_STRUCT *ads, void *mem) return NULL; } - if (pull_utf8_allocate(&unix_dn, utf8_dn) == (size_t)-1) { + if (!pull_utf8_allocate(&unix_dn, utf8_dn, &converted_size)) { DEBUG(0,("ads_get_dn: string conversion failure utf8 [%s]\n", utf8_dn )); return NULL; @@ -1287,6 +1298,7 @@ ADS_STATUS ads_gen_mod(ADS_STRUCT *ads, const char *mod_dn, ADS_MODLIST mods) { int ret,i; char *utf8_dn = NULL; + size_t converted_size; /* this control is needed to modify that contains a currently non-existent attribute (but allowable for the object) to run @@ -1300,7 +1312,7 @@ ADS_STATUS ads_gen_mod(ADS_STRUCT *ads, const char *mod_dn, ADS_MODLIST mods) controls[0] = &PermitModify; controls[1] = NULL; - if (push_utf8_allocate(&utf8_dn, mod_dn) == -1) { + if (!push_utf8_allocate(&utf8_dn, mod_dn, &converted_size)) { return ADS_ERROR_NT(NT_STATUS_NO_MEMORY); } @@ -1325,8 +1337,9 @@ ADS_STATUS ads_gen_add(ADS_STRUCT *ads, const char *new_dn, ADS_MODLIST mods) { int ret, i; char *utf8_dn = NULL; + size_t converted_size; - if (push_utf8_allocate(&utf8_dn, new_dn) == -1) { + if (!push_utf8_allocate(&utf8_dn, new_dn, &converted_size)) { DEBUG(1, ("ads_gen_add: push_utf8_allocate failed!")); return ADS_ERROR_NT(NT_STATUS_NO_MEMORY); } @@ -1351,7 +1364,8 @@ ADS_STATUS ads_del_dn(ADS_STRUCT *ads, char *del_dn) { int ret; char *utf8_dn = NULL; - if (push_utf8_allocate(&utf8_dn, del_dn) == -1) { + size_t converted_size; + if (!push_utf8_allocate(&utf8_dn, del_dn, &converted_size)) { DEBUG(1, ("ads_del_dn: push_utf8_allocate failed!")); return ADS_ERROR_NT(NT_STATUS_NO_MEMORY); } @@ -2012,6 +2026,7 @@ static bool ads_dump_field(ADS_STRUCT *ads, char *field, void **values, void *da { LDAPMessage *msg; TALLOC_CTX *ctx; + size_t converted_size; if (!(ctx = talloc_init("ads_process_results"))) return; @@ -2031,7 +2046,14 @@ static bool ads_dump_field(ADS_STRUCT *ads, char *field, void **values, void *da char *field; bool string; - pull_utf8_talloc(ctx, &field, utf8_field); + if (!pull_utf8_talloc(ctx, &field, utf8_field, + &converted_size)) + { + DEBUG(0,("ads_process_results: " + "pull_utf8_talloc failed: %s", + strerror(errno))); + } + string = fn(ads, field, NULL, data_area); if (string) { @@ -2127,18 +2149,16 @@ int ads_count_replies(ADS_STRUCT *ads, void *res) char **values; char *ret = NULL; char *ux_string; - size_t rc; + size_t converted_size; values = ldap_get_values(ads->ldap.ld, msg, field); if (!values) return NULL; - if (values[0]) { - rc = pull_utf8_talloc(mem_ctx, &ux_string, - values[0]); - if (rc != (size_t)-1) - ret = ux_string; - + if (values[0] && pull_utf8_talloc(mem_ctx, &ux_string, values[0], + &converted_size)) + { + ret = ux_string; } ldap_value_free(values); return ret; @@ -2159,6 +2179,7 @@ int ads_count_replies(ADS_STRUCT *ads, void *res) char **values; char **ret = NULL; int i; + size_t converted_size; values = ldap_get_values(ads->ldap.ld, msg, field); if (!values) @@ -2173,7 +2194,9 @@ int ads_count_replies(ADS_STRUCT *ads, void *res) } for (i=0;i<*num_values;i++) { - if (pull_utf8_talloc(mem_ctx, &ret[i], values[i]) == -1) { + if (!pull_utf8_talloc(mem_ctx, &ret[i], values[i], + &converted_size)) + { ldap_value_free(values); return NULL; } diff --git a/source3/libads/ldap_printer.c b/source3/libads/ldap_printer.c index 41f23b06a7..9935e2311a 100644 --- a/source3/libads/ldap_printer.c +++ b/source3/libads/ldap_printer.c @@ -103,17 +103,23 @@ static bool map_sz(TALLOC_CTX *ctx, ADS_MODLIST *mods, const REGISTRY_VALUE *value) { char *str_value = NULL; + size_t converted_size; ADS_STATUS status; if (value->type != REG_SZ) - return False; + return false; if (value->size && *((smb_ucs2_t *) value->data_p)) { - pull_ucs2_talloc(ctx, &str_value, (const smb_ucs2_t *) value->data_p); + if (!pull_ucs2_talloc(ctx, &str_value, + (const smb_ucs2_t *) value->data_p, + &converted_size)) + { + return false; + } status = ads_mod_str(ctx, mods, value->valuename, str_value); return ADS_ERR_OK(status); } - return True; + return true; } @@ -163,6 +169,7 @@ static bool map_multi_sz(TALLOC_CTX *ctx, ADS_MODLIST *mods, const REGISTRY_VALUE *value) { char **str_values = NULL; + size_t converted_size; smb_ucs2_t *cur_str = (smb_ucs2_t *) value->data_p; uint32 size = 0, num_vals = 0, i=0; ADS_STATUS status; @@ -185,9 +192,11 @@ static bool map_multi_sz(TALLOC_CTX *ctx, ADS_MODLIST *mods, (num_vals + 1) * sizeof(char *)); cur_str = (smb_ucs2_t *) value->data_p; - for (i=0; i < num_vals; i++) + for (i=0; i < num_vals; i++) { cur_str += pull_ucs2_talloc(ctx, &str_values[i], - cur_str); + cur_str, &converted_size) ? + converted_size : (size_t)-1; + } status = ads_mod_strlist(ctx, mods, value->valuename, (const char **) str_values); diff --git a/source3/libgpo/gpext/registry.c b/source3/libgpo/gpext/registry.c index 6cad8c796c..188a48ab49 100644 --- a/source3/libgpo/gpext/registry.c +++ b/source3/libgpo/gpext/registry.c @@ -258,6 +258,7 @@ static bool gp_reg_entry_from_file_entry(TALLOC_CTX *mem_ctx, char *key = NULL; char *value = NULL; enum gp_reg_action action = GP_REG_ACTION_NONE; + size_t converted_size; ZERO_STRUCTP(*reg_entry); @@ -268,12 +269,16 @@ static bool gp_reg_entry_from_file_entry(TALLOC_CTX *mem_ctx, if (strlen_w((const smb_ucs2_t *)file_entry->key.buffer) <= 0) return false; - if (!pull_ucs2_talloc(mem_ctx, &key, file_entry->key.buffer)) + if (!pull_ucs2_talloc(mem_ctx, &key, file_entry->key.buffer, + &converted_size)) + { return false; + } - if (strlen_w((const smb_ucs2_t *)file_entry->value.buffer) > 0) { - if (!pull_ucs2_talloc(mem_ctx, &value, - file_entry->value.buffer)) + if (strlen_w((const smb_ucs2_t *)file_entry->value.buffer) > 0 && + !pull_ucs2_talloc(mem_ctx, &value, file_entry->value.buffer, + &converted_size)) + { return false; } @@ -294,9 +299,13 @@ static bool gp_reg_entry_from_file_entry(TALLOC_CTX *mem_ctx, case REG_NONE: break; case REG_SZ: - data->v.sz.len = pull_ucs2_talloc(mem_ctx, - &data->v.sz.str, - (const smb_ucs2_t *)file_entry->data); + if (!pull_ucs2_talloc(mem_ctx, &data->v.sz.str, + (const smb_ucs2_t *) + file_entry->data, + &data->v.sz.len)) { + data->v.sz.len = -1; + } + break; case REG_DWORD_BIG_ENDIAN: case REG_EXPAND_SZ: diff --git a/source3/libgpo/gpo_ini.c b/source3/libgpo/gpo_ini.c index 6f1593c2c2..54aaffa477 100644 --- a/source3/libgpo/gpo_ini.c +++ b/source3/libgpo/gpo_ini.c @@ -57,6 +57,7 @@ static NTSTATUS convert_file_from_ucs2(TALLOC_CTX *mem_ctx, char *tmp_name = NULL; NTSTATUS status; size_t n = 0; + size_t converted_size; if (!filename_out) { return NT_STATUS_INVALID_PARAMETER; @@ -81,10 +82,9 @@ static NTSTATUS convert_file_from_ucs2(TALLOC_CTX *mem_ctx, goto out; } - n = convert_string_talloc(mem_ctx, CH_UTF16LE, CH_UNIX, - data_in, n, &data_out, False); - - if (n == -1) { + if (!convert_string_talloc(mem_ctx, CH_UTF16LE, CH_UNIX, data_in, n, + &data_out, &converted_size, False)) + { status = NT_STATUS_INVALID_BUFFER_SIZE; goto out; } @@ -99,10 +99,10 @@ static NTSTATUS convert_file_from_ucs2(TALLOC_CTX *mem_ctx, DEBUG(11,("convert_file_from_ucs2: " "%s skipping utf8 BOM\n", tmp_name)); data_out += 3; - n -= 3; + converted_size -= 3; } - if (sys_write(tmp_fd, data_out, n) != n) { + if (sys_write(tmp_fd, data_out, converted_size) != converted_size) { status = map_nt_error_from_unix(errno); goto out; } diff --git a/source3/librpc/ndr/ndr_string.c b/source3/librpc/ndr/ndr_string.c index e553443bd8..1c0675849c 100644 --- a/source3/librpc/ndr/ndr_string.c +++ b/source3/librpc/ndr/ndr_string.c @@ -30,7 +30,7 @@ _PUBLIC_ enum ndr_err_code ndr_pull_string(struct ndr_pull *ndr, int ndr_flags, char *as=NULL; uint32_t len1, ofs, len2; uint16_t len3; - int ret; + size_t converted_size; int chset = CH_UTF16; unsigned byte_mul = 2; unsigned flags = ndr->flags; @@ -81,15 +81,15 @@ _PUBLIC_ enum ndr_err_code ndr_pull_string(struct ndr_pull *ndr, int ndr_flags, if (len2 == 0) { as = talloc_strdup(ndr->current_mem_ctx, ""); } else { - ret = convert_string_talloc(ndr->current_mem_ctx, - chset, CH_UNIX, - ndr->data+ndr->offset, - (len2 + c_len_term)*byte_mul, - (void **)(void *)&as, - false); - if (ret == -1) { - return ndr_pull_error(ndr, NDR_ERR_CHARCNV, - "Bad character conversion"); + if (!convert_string_talloc(ndr->current_mem_ctx, chset, + CH_UNIX, + ndr->data+ndr->offset, + (len2 + c_len_term)*byte_mul, + (void **)(void *)&as, + &converted_size, false)) + { + return ndr_pull_error(ndr, NDR_ERR_CHARCNV, + "Bad char conversion"); } } NDR_CHECK(ndr_pull_advance(ndr, (len2 + c_len_term)*byte_mul)); @@ -119,15 +119,15 @@ _PUBLIC_ enum ndr_err_code ndr_pull_string(struct ndr_pull *ndr, int ndr_flags, if (len1 == 0) { as = talloc_strdup(ndr->current_mem_ctx, ""); } else { - ret = convert_string_talloc(ndr->current_mem_ctx, - chset, CH_UNIX, - ndr->data+ndr->offset, - (len1 + c_len_term)*byte_mul, - (void **)(void *)&as, - false); - if (ret == -1) { + if (!convert_string_talloc(ndr->current_mem_ctx, chset, + CH_UNIX, + ndr->data+ndr->offset, + (len1 + c_len_term)*byte_mul, + (void **)(void *)&as, + &converted_size, false)) + { return ndr_pull_error(ndr, NDR_ERR_CHARCNV, - "Bad character conversion"); + "Bad char conversion"); } } NDR_CHECK(ndr_pull_advance(ndr, (len1 + c_len_term)*byte_mul)); @@ -158,15 +158,15 @@ _PUBLIC_ enum ndr_err_code ndr_pull_string(struct ndr_pull *ndr, int ndr_flags, if (len1 == 0) { as = talloc_strdup(ndr->current_mem_ctx, ""); } else { - ret = convert_string_talloc(ndr->current_mem_ctx, - chset, CH_UNIX, - ndr->data+ndr->offset, - (len1 + c_len_term)*byte_mul, - (void **)(void *)&as, - false); - if (ret == -1) { + if (!convert_string_talloc(ndr->current_mem_ctx, chset, + CH_UNIX, + ndr->data+ndr->offset, + (len1 + c_len_term)*byte_mul, + (void **)(void *)&as, + &converted_size, false)) + { return ndr_pull_error(ndr, NDR_ERR_CHARCNV, - "Bad character conversion"); + "Bad char conversion"); } } NDR_CHECK(ndr_pull_advance(ndr, (len1 + c_len_term)*byte_mul)); @@ -193,15 +193,15 @@ _PUBLIC_ enum ndr_err_code ndr_pull_string(struct ndr_pull *ndr, int ndr_flags, if (len3 == 0) { as = talloc_strdup(ndr->current_mem_ctx, ""); } else { - ret = convert_string_talloc(ndr->current_mem_ctx, - chset, CH_UNIX, - ndr->data+ndr->offset, - (len3 + c_len_term)*byte_mul, - (void **)(void *)&as, - false); - if (ret == -1) { + if (!convert_string_talloc(ndr->current_mem_ctx, chset, + CH_UNIX, + ndr->data+ndr->offset, + (len3 + c_len_term)*byte_mul, + (void **)(void *)&as, + &converted_size, false)) + { return ndr_pull_error(ndr, NDR_ERR_CHARCNV, - "Bad character conversion"); + "Bad char conversion"); } } NDR_CHECK(ndr_pull_advance(ndr, (len3 + c_len_term)*byte_mul)); @@ -226,15 +226,14 @@ _PUBLIC_ enum ndr_err_code ndr_pull_string(struct ndr_pull *ndr, int ndr_flags, if (len3 == 0) { as = talloc_strdup(ndr->current_mem_ctx, ""); } else { - ret = convert_string_talloc(ndr->current_mem_ctx, - chset, CH_UNIX, - ndr->data+ndr->offset, - len3, - (void **)(void *)&as, - false); - if (ret == -1) { + if (!convert_string_talloc(ndr->current_mem_ctx, chset, + CH_UNIX, + ndr->data+ndr->offset, len3, + (void **)(void *)&as, + &converted_size, false)) + { return ndr_pull_error(ndr, NDR_ERR_CHARCNV, - "Bad character conversion"); + "Bad char conversion"); } } NDR_CHECK(ndr_pull_advance(ndr, len3)); @@ -247,15 +246,13 @@ _PUBLIC_ enum ndr_err_code ndr_pull_string(struct ndr_pull *ndr, int ndr_flags, } else { len1 = utf16_len_n(ndr->data+ndr->offset, ndr->data_size - ndr->offset); } - ret = convert_string_talloc(ndr->current_mem_ctx, - chset, CH_UNIX, - ndr->data+ndr->offset, - len1, - (void **)(void *)&as, - false); - if (ret == -1) { + if (!convert_string_talloc(ndr->current_mem_ctx, chset, CH_UNIX, + ndr->data+ndr->offset, len1, + (void **)(void *)&as, + &converted_size, false)) + { return ndr_pull_error(ndr, NDR_ERR_CHARCNV, - "Bad character conversion"); + "Bad char conversion"); } NDR_CHECK(ndr_pull_advance(ndr, len1)); *s = as; @@ -265,15 +262,13 @@ _PUBLIC_ enum ndr_err_code ndr_pull_string(struct ndr_pull *ndr, int ndr_flags, case LIBNDR_FLAG_STR_FIXLEN32: len1 = (flags & LIBNDR_FLAG_STR_FIXLEN32)?32:15; NDR_PULL_NEED_BYTES(ndr, len1*byte_mul); - ret = convert_string_talloc(ndr->current_mem_ctx, - chset, CH_UNIX, - ndr->data+ndr->offset, - len1*byte_mul, - (void **)(void *)&as, - false); - if (ret == -1) { + if (!convert_string_talloc(ndr->current_mem_ctx, chset, CH_UNIX, + ndr->data+ndr->offset, len1*byte_mul, + (void **)(void *)&as, + &converted_size, false)) + { return ndr_pull_error(ndr, NDR_ERR_CHARCNV, - "Bad character conversion"); + "Bad char conversion"); } NDR_CHECK(ndr_pull_advance(ndr, len1*byte_mul)); *s = as; @@ -291,15 +286,14 @@ _PUBLIC_ enum ndr_err_code ndr_pull_string(struct ndr_pull *ndr, int ndr_flags, if (len1 == 0) { as = talloc_strdup(ndr->current_mem_ctx, ""); } else { - ret = convert_string_talloc(ndr->current_mem_ctx, - chset, CH_UNIX, - ndr->data+ndr->offset, - len1, - (void **)(void *)&as, - false); - if (ret == -1) { + if (!convert_string_talloc(ndr->current_mem_ctx, chset, + CH_UNIX, + ndr->data+ndr->offset, len1, + (void **)(void *)&as, + &converted_size, false)) + { return ndr_pull_error(ndr, NDR_ERR_CHARCNV, - "Bad character conversion"); + "Bad char conversion"); } } NDR_CHECK(ndr_pull_advance(ndr, len1)); @@ -357,11 +351,11 @@ _PUBLIC_ enum ndr_err_code ndr_push_string(struct ndr_push *ndr, int ndr_flags, LIBNDR_FLAG_STR_FIXLEN32))) { s_len++; } - d_len = convert_string_talloc(ndr, CH_UNIX, chset, s, s_len, - (void **)(void *)&dest, false); - if (d_len == -1) { + if (!convert_string_talloc(ndr, CH_UNIX, chset, s, s_len, + (void **)(void *)&dest, &d_len, false)) + { return ndr_push_error(ndr, NDR_ERR_CHARCNV, - "Bad character conversion"); + "Bad char conversion"); } if (flags & LIBNDR_FLAG_STR_BYTESIZE) { @@ -408,7 +402,7 @@ _PUBLIC_ enum ndr_err_code ndr_push_string(struct ndr_push *ndr, int ndr_flags, uint32_t pad_len = fix_len - d_len; if (d_len > fix_len) { return ndr_push_error(ndr, NDR_ERR_CHARCNV, - "Bad character conversion"); + "Bad char conversion"); } NDR_CHECK(ndr_push_bytes(ndr, dest, d_len)); if (pad_len != 0) { @@ -679,7 +673,8 @@ _PUBLIC_ enum ndr_err_code ndr_check_string_terminator(struct ndr_pull *ndr, uin _PUBLIC_ enum ndr_err_code ndr_pull_charset(struct ndr_pull *ndr, int ndr_flags, const char **var, uint32_t length, uint8_t byte_mul, charset_t chset) { - int ret; + size_t converted_size; + if (length == 0) { *var = talloc_strdup(ndr->current_mem_ctx, ""); return NDR_ERR_SUCCESS; @@ -691,14 +686,13 @@ _PUBLIC_ enum ndr_err_code ndr_pull_charset(struct ndr_pull *ndr, int ndr_flags, NDR_PULL_NEED_BYTES(ndr, length*byte_mul); - ret = convert_string_talloc(ndr->current_mem_ctx, - chset, CH_UNIX, - ndr->data+ndr->offset, - length*byte_mul, - discard_const_p(void *, var), false); - if (ret == -1) { + if (!convert_string_talloc(ndr->current_mem_ctx, chset, CH_UNIX, + ndr->data+ndr->offset, length*byte_mul, + discard_const_p(void *, var), + &converted_size, false)) + { return ndr_pull_error(ndr, NDR_ERR_CHARCNV, - "Bad character conversion"); + "Bad char conversion"); } NDR_CHECK(ndr_pull_advance(ndr, length*byte_mul)); @@ -721,7 +715,7 @@ _PUBLIC_ enum ndr_err_code ndr_push_charset(struct ndr_push *ndr, int ndr_flags, ndr->data+ndr->offset, required, false); if (ret == -1) { return ndr_push_error(ndr, NDR_ERR_CHARCNV, - "Bad character conversion"); + "Bad char conversion"); } /* Make sure the remaining part of the string is filled with zeroes */ diff --git a/source3/libsmb/clikrb5.c b/source3/libsmb/clikrb5.c index c289740ab2..7688b0bd12 100644 --- a/source3/libsmb/clikrb5.c +++ b/source3/libsmb/clikrb5.c @@ -52,8 +52,9 @@ { krb5_error_code ret; char *utf8_name; + size_t converted_size; - if (push_utf8_allocate(&utf8_name, name) == (size_t)-1) { + if (!push_utf8_allocate(&utf8_name, name, &converted_size)) { return ENOMEM; } @@ -73,9 +74,10 @@ static krb5_error_code smb_krb5_parse_name_norealm_conv(krb5_context context, { krb5_error_code ret; char *utf8_name; + size_t converted_size; *principal = NULL; - if (push_utf8_allocate(&utf8_name, name) == (size_t)-1) { + if (!push_utf8_allocate(&utf8_name, name, &converted_size)) { return ENOMEM; } @@ -96,6 +98,7 @@ static krb5_error_code smb_krb5_parse_name_norealm_conv(krb5_context context, { krb5_error_code ret; char *utf8_name; + size_t converted_size; *unix_name = NULL; ret = krb5_unparse_name(context, principal, &utf8_name); @@ -103,7 +106,7 @@ static krb5_error_code smb_krb5_parse_name_norealm_conv(krb5_context context, return ret; } - if (pull_utf8_allocate(unix_name, utf8_name)==-1) { + if (!pull_utf8_allocate(unix_name, utf8_name, &converted_size)) { krb5_free_unparsed_name(context, utf8_name); return ENOMEM; } diff --git a/source3/libsmb/clirap.c b/source3/libsmb/clirap.c index 8c167e1257..cf4f4987cf 100644 --- a/source3/libsmb/clirap.c +++ b/source3/libsmb/clirap.c @@ -904,14 +904,14 @@ bool cli_qpathinfo_streams(struct cli_state *cli, const char *fname, tmp_buf[nlen] = 0; tmp_buf[nlen+1] = 0; - size = convert_string_talloc(streams, CH_UTF16, CH_UNIX, - tmp_buf, nlen+2, &vstr, - false); - TALLOC_FREE(tmp_buf); - - if (size == -1) { + if (!convert_string_talloc(streams, CH_UTF16, CH_UNIX, tmp_buf, + nlen+2, &vstr, &size, false)) + { + TALLOC_FREE(tmp_buf); goto fail; } + + TALLOC_FREE(tmp_buf); streams[num_streams].name = (char *)vstr; num_streams++; diff --git a/source3/libsmb/smbencrypt.c b/source3/libsmb/smbencrypt.c index 11f8780a47..f339b6b9f6 100644 --- a/source3/libsmb/smbencrypt.c +++ b/source3/libsmb/smbencrypt.c @@ -172,15 +172,15 @@ bool ntv2_owf_gen(const uchar owf[16], HMACMD5Context ctx; - user_byte_len = push_ucs2_allocate(&user, user_in); - if (user_byte_len == (size_t)-1) { - DEBUG(0, ("push_uss2_allocate() for user returned -1 (probably malloc() failure)\n")); + if (!push_ucs2_allocate(&user, user_in, &user_byte_len)) { + DEBUG(0, ("push_uss2_allocate() for user failed: %s\n", + strerror(errno))); return False; } - domain_byte_len = push_ucs2_allocate(&domain, domain_in); - if (domain_byte_len == (size_t)-1) { - DEBUG(0, ("push_uss2_allocate() for domain returned -1 (probably malloc() failure)\n")); + if (!push_ucs2_allocate(&domain, domain_in, &domain_byte_len)) { + DEBUG(0, ("push_uss2_allocate() for domain failed: %s\n", + strerror(errno))); return False; } diff --git a/source3/modules/vfs_catia.c b/source3/modules/vfs_catia.c index 8b56be6cea..7ffb310975 100644 --- a/source3/modules/vfs_catia.c +++ b/source3/modules/vfs_catia.c @@ -36,12 +36,13 @@ static char *catia_string_replace(TALLOC_CTX *ctx, smb_ucs2_t *ptr = NULL; smb_ucs2_t old = oldc; char *ret = NULL; + size_t converted_size; if (!s) { return NULL; } - if (push_ucs2_talloc(ctx, &tmpbuf, s) == -1) { + if (!push_ucs2_talloc(ctx, &tmpbuf, s, &converted_size)) { return NULL; } @@ -53,7 +54,7 @@ static char *catia_string_replace(TALLOC_CTX *ctx, } } - if (pull_ucs2_talloc(ctx, &ret, tmpbuf) == -1) { + if (!pull_ucs2_talloc(ctx, &ret, tmpbuf, &converted_size)) { TALLOC_FREE(tmpbuf); return NULL; } diff --git a/source3/passdb/pdb_ldap.c b/source3/passdb/pdb_ldap.c index cf5b72bc7c..9ce659e818 100644 --- a/source3/passdb/pdb_ldap.c +++ b/source3/passdb/pdb_ldap.c @@ -1699,6 +1699,7 @@ static NTSTATUS ldapsam_modify_entry(struct pdb_methods *my_methods, struct berval *retdata = NULL; char *utf8_password; char *utf8_dn; + size_t converted_size; if (!ldap_state->is_nds_ldap) { @@ -1710,11 +1711,14 @@ static NTSTATUS ldapsam_modify_entry(struct pdb_methods *my_methods, } } - if (push_utf8_allocate(&utf8_password, pdb_get_plaintext_passwd(newpwd)) == (size_t)-1) { + if (!push_utf8_allocate(&utf8_password, + pdb_get_plaintext_passwd(newpwd), + &converted_size)) + { return NT_STATUS_NO_MEMORY; } - if (push_utf8_allocate(&utf8_dn, dn) == (size_t)-1) { + if (!push_utf8_allocate(&utf8_dn, dn, &converted_size)) { SAFE_FREE(utf8_password); return NT_STATUS_NO_MEMORY; } @@ -4404,6 +4408,7 @@ static bool ldapuser2displayentry(struct ldap_search_state *state, struct samr_displayentry *result) { char **vals; + size_t converted_size; DOM_SID sid; uint32 acct_flags; @@ -4429,27 +4434,40 @@ static bool ldapuser2displayentry(struct ldap_search_state *state, DEBUG(5, ("\"uid\" not found\n")); return False; } - pull_utf8_talloc(mem_ctx, - CONST_DISCARD(char **, &result->account_name), - vals[0]); + if (!pull_utf8_talloc(mem_ctx, + CONST_DISCARD(char **, &result->account_name), + vals[0], &converted_size)) + { + DEBUG(0,("ldapuser2displayentry: pull_utf8_talloc failed: %s", + strerror(errno))); + } + ldap_value_free(vals); vals = ldap_get_values(ld, entry, "displayName"); if ((vals == NULL) || (vals[0] == NULL)) DEBUG(8, ("\"displayName\" not found\n")); - else - pull_utf8_talloc(mem_ctx, - CONST_DISCARD(char **, &result->fullname), - vals[0]); + else if (!pull_utf8_talloc(mem_ctx, + CONST_DISCARD(char **, &result->fullname), + vals[0], &converted_size)) + { + DEBUG(0,("ldapuser2displayentry: pull_utf8_talloc failed: %s", + strerror(errno))); + } + ldap_value_free(vals); vals = ldap_get_values(ld, entry, "description"); if ((vals == NULL) || (vals[0] == NULL)) DEBUG(8, ("\"description\" not found\n")); - else - pull_utf8_talloc(mem_ctx, - CONST_DISCARD(char **, &result->description), - vals[0]); + else if (!pull_utf8_talloc(mem_ctx, + CONST_DISCARD(char **, &result->description), + vals[0], &converted_size)) + { + DEBUG(0,("ldapuser2displayentry: pull_utf8_talloc failed: %s", + strerror(errno))); + } + ldap_value_free(vals); if ((result->account_name == NULL) || @@ -4536,6 +4554,7 @@ static bool ldapgroup2displayentry(struct ldap_search_state *state, struct samr_displayentry *result) { char **vals; + size_t converted_size; DOM_SID sid; uint16 group_type; @@ -4575,14 +4594,22 @@ static bool ldapgroup2displayentry(struct ldap_search_state *state, DEBUG(5, ("\"cn\" not found\n")); return False; } - pull_utf8_talloc(mem_ctx, - CONST_DISCARD(char **, &result->account_name), - vals[0]); + if (!pull_utf8_talloc(mem_ctx, + CONST_DISCARD(char **, + &result->account_name), + vals[0], &converted_size)) + { + DEBUG(0,("ldapgroup2displayentry: pull_utf8_talloc " + "failed: %s", strerror(errno))); + } } - else { - pull_utf8_talloc(mem_ctx, - CONST_DISCARD(char **, &result->account_name), - vals[0]); + else if (!pull_utf8_talloc(mem_ctx, + CONST_DISCARD(char **, + &result->account_name), + vals[0], &converted_size)) + { + DEBUG(0,("ldapgroup2displayentry: pull_utf8_talloc failed: %s", + strerror(errno))); } ldap_value_free(vals); @@ -4590,10 +4617,13 @@ static bool ldapgroup2displayentry(struct ldap_search_state *state, vals = ldap_get_values(ld, entry, "description"); if ((vals == NULL) || (vals[0] == NULL)) DEBUG(8, ("\"description\" not found\n")); - else - pull_utf8_talloc(mem_ctx, - CONST_DISCARD(char **, &result->description), - vals[0]); + else if (!pull_utf8_talloc(mem_ctx, + CONST_DISCARD(char **, &result->description), + vals[0], &converted_size)) + { + DEBUG(0,("ldapgroup2displayentry: pull_utf8_talloc failed: %s", + strerror(errno))); + } ldap_value_free(vals); if ((result->account_name == NULL) || diff --git a/source3/passdb/secrets.c b/source3/passdb/secrets.c index 34a87bd0d0..a7223b7e9f 100644 --- a/source3/passdb/secrets.c +++ b/source3/passdb/secrets.c @@ -685,6 +685,7 @@ bool secrets_store_trusted_domain_password(const char* domain, const char* pwd, { smb_ucs2_t *uni_dom_name; bool ret; + size_t converted_size; /* packing structures */ uint8 *pass_buf = NULL; @@ -693,7 +694,7 @@ bool secrets_store_trusted_domain_password(const char* domain, const char* pwd, struct trusted_dom_pass pass; ZERO_STRUCT(pass); - if (push_ucs2_allocate(&uni_dom_name, domain) == (size_t)-1) { + if (!push_ucs2_allocate(&uni_dom_name, domain, &converted_size)) { DEBUG(0, ("Could not convert domain name %s to unicode\n", domain)); return False; @@ -926,7 +927,7 @@ struct list_trusted_domains_state { static int list_trusted_domain(struct db_record *rec, void *private_data) { const size_t prefix_len = strlen(SECRETS_DOMTRUST_ACCT_PASS); - size_t packed_size = 0; + size_t converted_size, packed_size = 0; struct trusted_dom_pass pass; struct trustdom_info *dom_info; @@ -960,8 +961,8 @@ static int list_trusted_domain(struct db_record *rec, void *private_data) return 0; } - if (pull_ucs2_talloc(dom_info, &dom_info->name, - pass.uni_name) == (size_t)-1) { + if (!pull_ucs2_talloc(dom_info, &dom_info->name, pass.uni_name, + &converted_size)) { DEBUG(2, ("pull_ucs2_talloc failed\n")); TALLOC_FREE(dom_info); return 0; diff --git a/source3/printing/nt_printing.c b/source3/printing/nt_printing.c index a66b1e5c5f..3a7f1174bd 100644 --- a/source3/printing/nt_printing.c +++ b/source3/printing/nt_printing.c @@ -3242,6 +3242,7 @@ static WERROR nt_printer_publish_ads(ADS_STRUCT *ads, const char *attrs[] = {"objectGUID", NULL}; struct GUID guid; WERROR win_rc = WERR_OK; + size_t converted_size; DEBUG(5, ("publishing printer %s\n", printer->info_2->printername)); @@ -3264,13 +3265,13 @@ static WERROR nt_printer_publish_ads(ADS_STRUCT *ads, return WERR_SERVER_UNAVAILABLE; } /* Now convert to CH_UNIX. */ - if (pull_utf8_allocate(&srv_dn, srv_dn_utf8) == (size_t)-1) { + if (!pull_utf8_allocate(&srv_dn, srv_dn_utf8, &converted_size)) { ldap_memfree(srv_dn_utf8); ldap_memfree(srv_cn_utf8); ads_destroy(&ads); return WERR_SERVER_UNAVAILABLE; } - if (pull_utf8_allocate(&srv_cn_0, srv_cn_utf8[0]) == (size_t)-1) { + if (!pull_utf8_allocate(&srv_cn_0, srv_cn_utf8[0], &converted_size)) { ldap_memfree(srv_dn_utf8); ldap_memfree(srv_cn_utf8); ads_destroy(&ads); diff --git a/source3/rpcclient/cmd_wkssvc.c b/source3/rpcclient/cmd_wkssvc.c index fbf483bd2b..d17ea01370 100644 --- a/source3/rpcclient/cmd_wkssvc.c +++ b/source3/rpcclient/cmd_wkssvc.c @@ -103,10 +103,9 @@ static WERROR cmd_wkssvc_messagebuffersend(struct rpc_pipe_client *cli, message = argv[1]; } - message_size = push_ucs2_talloc(mem_ctx, - &message_buffer, - message); - if (message_size == -1) { + if (!push_ucs2_talloc(mem_ctx, &message_buffer, message, + &message_size)) + { return WERR_NOMEM; } diff --git a/source3/smbd/lanman.c b/source3/smbd/lanman.c index 413b916f7b..d6c76c54c1 100644 --- a/source3/smbd/lanman.c +++ b/source3/smbd/lanman.c @@ -1896,6 +1896,7 @@ static bool api_RNetShareAdd(connection_struct *conn,uint16 vuid, unsigned int offset; int snum; int res = ERRunsup; + size_t converted_size; if (!str1 || !str2 || !p) { return False; @@ -1956,7 +1957,13 @@ static bool api_RNetShareAdd(connection_struct *conn,uint16 vuid, return False; } - pull_ascii_talloc(talloc_tos(), &pathname, offset? (data+offset) : ""); + if (!pull_ascii_talloc(talloc_tos(), &pathname, + offset ? (data+offset) : "", &converted_size)) + { + DEBUG(0,("api_RNetShareAdd: pull_ascii_talloc failed: %s", + strerror(errno))); + } + if (!pathname) { return false; } diff --git a/source3/smbd/mangle_hash.c b/source3/smbd/mangle_hash.c index 1dc9c67dcc..69ecf77834 100644 --- a/source3/smbd/mangle_hash.c +++ b/source3/smbd/mangle_hash.c @@ -294,8 +294,7 @@ static bool is_8_3(const char *fname, bool check_case, bool allow_wildcards, if (strlen(f) > 12) return False; - size = push_ucs2_allocate(&ucs2name, f); - if (size == (size_t)-1) { + if (!push_ucs2_allocate(&ucs2name, f, &size)) { DEBUG(0,("is_8_3: internal error push_ucs2_allocate() failed!\n")); goto done; } @@ -604,9 +603,11 @@ static bool must_mangle(const char *name, { smb_ucs2_t *name_ucs2 = NULL; NTSTATUS status; + size_t converted_size; + magic_char = lp_magicchar(p); - if (push_ucs2_allocate(&name_ucs2, name) == (size_t)-1) { + if (!push_ucs2_allocate(&name_ucs2, name, &converted_size)) { DEBUG(0, ("push_ucs2_allocate failed!\n")); return False; } @@ -637,12 +638,14 @@ static bool hash_name_to_8_3(const char *in, const struct share_params *p) { smb_ucs2_t *in_ucs2 = NULL; + size_t converted_size; + magic_char = lp_magicchar(p); DEBUG(5,("hash_name_to_8_3( %s, cache83 = %s)\n", in, cache83 ? "True" : "False")); - if (push_ucs2_allocate(&in_ucs2, in) == (size_t)-1) { + if (!push_ucs2_allocate(&in_ucs2, in, &converted_size)) { DEBUG(0, ("push_ucs2_allocate failed!\n")); return False; } diff --git a/source3/smbd/message.c b/source3/smbd/message.c index a870f03df9..62df5c37eb 100644 --- a/source3/smbd/message.c +++ b/source3/smbd/message.c @@ -45,7 +45,7 @@ static void msg_deliver(struct msg_state *state) int i; int fd; char *msg; - int len; + size_t len; ssize_t sz; fstring alpha_buf; char *s; @@ -72,18 +72,17 @@ static void msg_deliver(struct msg_state *state) * Incoming message is in DOS codepage format. Convert to UNIX. */ - len = convert_string_talloc( - talloc_tos(), CH_DOS, CH_UNIX, state->msg, - talloc_get_size(state->msg), (void *)&msg, true); - - if (len == -1) { + if (!convert_string_talloc(talloc_tos(), CH_DOS, CH_UNIX, state->msg, + talloc_get_size(state->msg), (void *)&msg, + &len, true)) { DEBUG(3, ("Conversion failed, delivering message in DOS " "codepage format\n")); msg = state->msg; } for (i = 0; i < len; i++) { - if ((msg[i] == '\r') && (i < (len-1)) && (msg[i+1] == '\n')) { + if ((msg[i] == '\r') && + (i < (len-1)) && (msg[i+1] == '\n')) { continue; } sz = write(fd, &msg[i], 1); diff --git a/source3/smbd/negprot.c b/source3/smbd/negprot.c index 9f56949eeb..84f111fb02 100644 --- a/source3/smbd/negprot.c +++ b/source3/smbd/negprot.c @@ -516,6 +516,7 @@ void reply_negprot(struct smb_request *req) int num_cliprotos; char **cliprotos; int i; + size_t converted_size; static bool done_negprot = False; @@ -555,8 +556,8 @@ void reply_negprot(struct smb_request *req) cliprotos = tmp; - if (pull_ascii_talloc(cliprotos, &cliprotos[num_cliprotos], p) - == (size_t)-1) { + if (!pull_ascii_talloc(cliprotos, &cliprotos[num_cliprotos], p, + &converted_size)) { DEBUG(0, ("pull_ascii_talloc failed\n")); TALLOC_FREE(cliprotos); reply_nterror(req, NT_STATUS_NO_MEMORY); diff --git a/source3/smbd/trans2.c b/source3/smbd/trans2.c index d5435533f9..72688bbd66 100644 --- a/source3/smbd/trans2.c +++ b/source3/smbd/trans2.c @@ -178,7 +178,7 @@ NTSTATUS get_ea_names_from_file(TALLOC_CTX *mem_ctx, connection_struct *conn, char *p; char **names, **tmp; size_t num_names; - ssize_t sizeret; + ssize_t sizeret = -1; if (!lp_ea_support(SNUM(conn))) { *pnames = NULL; @@ -504,7 +504,7 @@ NTSTATUS set_ea(connection_struct *conn, files_struct *fsp, const char *fname, s static struct ea_list *read_ea_name_list(TALLOC_CTX *ctx, const char *pdata, size_t data_size) { struct ea_list *ea_list_head = NULL; - size_t offset = 0; + size_t converted_size, offset = 0; while (offset + 2 < data_size) { struct ea_list *eal = TALLOC_ZERO_P(ctx, struct ea_list); @@ -522,7 +522,11 @@ static struct ea_list *read_ea_name_list(TALLOC_CTX *ctx, const char *pdata, siz if (pdata[offset + namelen] != '\0') { return NULL; } - pull_ascii_talloc(ctx, &eal->ea.name, &pdata[offset]); + if (!pull_ascii_talloc(ctx, &eal->ea.name, &pdata[offset], + &converted_size)) { + DEBUG(0,("read_ea_name_list: pull_ascii_talloc " + "failed: %s", strerror(errno))); + } if (!eal->ea.name) { return NULL; } @@ -544,6 +548,7 @@ struct ea_list *read_ea_list_entry(TALLOC_CTX *ctx, const char *pdata, size_t da struct ea_list *eal = TALLOC_ZERO_P(ctx, struct ea_list); uint16 val_len; unsigned int namelen; + size_t converted_size; if (!eal) { return NULL; @@ -565,7 +570,10 @@ struct ea_list *read_ea_list_entry(TALLOC_CTX *ctx, const char *pdata, size_t da if (pdata[namelen + 4] != '\0') { return NULL; } - pull_ascii_talloc(ctx, &eal->ea.name, pdata + 4); + if (!pull_ascii_talloc(ctx, &eal->ea.name, pdata + 4, &converted_size)) { + DEBUG(0,("read_ea_list_entry: pull_ascii_talloc failed: %s", + strerror(errno))); + } if (!eal->ea.name) { return NULL; } @@ -3665,10 +3673,10 @@ static NTSTATUS marshall_stream_info(unsigned int num_streams, size_t namelen; smb_ucs2_t *namebuf; - namelen = push_ucs2_talloc(talloc_tos(), &namebuf, - streams[i].name); - - if ((namelen == (size_t)-1) || (namelen <= 2)) { + if (!push_ucs2_talloc(talloc_tos(), &namebuf, + streams[i].name, &namelen) || + namelen <= 2) + { return NT_STATUS_INVALID_PARAMETER; } diff --git a/source3/torture/t_push_ucs2.c b/source3/torture/t_push_ucs2.c index 8d327acfa5..b9bf87ba54 100644 --- a/source3/torture/t_push_ucs2.c +++ b/source3/torture/t_push_ucs2.c @@ -12,9 +12,10 @@ static int check_push_ucs2(const char *orig) smb_ucs2_t *dest = NULL; char *orig2 = NULL; int ret; + size_t converted_size; - push_ucs2_allocate(&dest, orig); - pull_ucs2_allocate(&orig2, dest); + push_ucs2_allocate(&dest, orig, &converted_size); + pull_ucs2_allocate(&orig2, dest, &converted_size); ret = strcmp(orig, orig2); if (ret) { fprintf(stderr, "orig: %s\n", orig); diff --git a/source3/utils/ntlm_auth_diagnostics.c b/source3/utils/ntlm_auth_diagnostics.c index dfd05ad51c..dcdc8e9a40 100644 --- a/source3/utils/ntlm_auth_diagnostics.c +++ b/source3/utils/ntlm_auth_diagnostics.c @@ -445,6 +445,7 @@ static bool test_plaintext(enum ntlm_break break_which) DATA_BLOB lm_response = data_blob_null; char *password; smb_ucs2_t *nt_response_ucs2; + size_t converted_size; uchar user_session_key[16]; uchar lm_key[16]; @@ -457,7 +458,9 @@ static bool test_plaintext(enum ntlm_break break_which) flags |= WBFLAG_PAM_LMKEY; flags |= WBFLAG_PAM_USER_SESSION_KEY; - if ((push_ucs2_allocate(&nt_response_ucs2, opt_password)) == -1) { + if (!push_ucs2_allocate(&nt_response_ucs2, opt_password, + &converted_size)) + { DEBUG(0, ("push_ucs2_allocate failed!\n")); exit(1); } diff --git a/source3/web/statuspage.c b/source3/web/statuspage.c index eda53b66ab..ce24c7cddd 100644 --- a/source3/web/statuspage.c +++ b/source3/web/statuspage.c @@ -123,6 +123,7 @@ static void print_share_mode(const struct share_mode_entry *e, { char *utf8_fname; int deny_mode; + size_t converted_size; if (!is_valid_share_mode_entry(e)) { return; @@ -169,7 +170,7 @@ static void print_share_mode(const struct share_mode_entry *e, printf("NONE "); printf("</td>"); - push_utf8_allocate(&utf8_fname, fname); + push_utf8_allocate(&utf8_fname, fname, &converted_size); printf("<td>%s</td><td>%s</td></tr>\n", utf8_fname,tstring(talloc_tos(),e->time.tv_sec)); SAFE_FREE(utf8_fname); diff --git a/source3/web/swat.c b/source3/web/swat.c index 6d8f4cae06..3e14d2d098 100644 --- a/source3/web/swat.c +++ b/source3/web/swat.c @@ -228,6 +228,7 @@ static void show_parameter(int snum, struct parm_struct *parm) int i; void *ptr = parm->ptr; char *utf8_s1, *utf8_s2; + size_t converted_size; TALLOC_CTX *ctx = talloc_stackframe(); if (parm->p_class == P_LOCAL && snum >= 0) { @@ -252,12 +253,12 @@ static void show_parameter(int snum, struct parm_struct *parm) for (;*list;list++) { /* enclose in HTML encoded quotes if the string contains a space */ if ( strchr_m(*list, ' ') ) { - push_utf8_allocate(&utf8_s1, *list); - push_utf8_allocate(&utf8_s2, ((*(list+1))?", ":"")); + push_utf8_allocate(&utf8_s1, *list, &converted_size); + push_utf8_allocate(&utf8_s2, ((*(list+1))?", ":""), &converted_size); printf(""%s"%s", utf8_s1, utf8_s2); } else { - push_utf8_allocate(&utf8_s1, *list); - push_utf8_allocate(&utf8_s2, ((*(list+1))?", ":"")); + push_utf8_allocate(&utf8_s1, *list, &converted_size); + push_utf8_allocate(&utf8_s2, ((*(list+1))?", ":""), &converted_size); printf("%s%s", utf8_s1, utf8_s2); } SAFE_FREE(utf8_s1); @@ -282,7 +283,7 @@ static void show_parameter(int snum, struct parm_struct *parm) case P_STRING: case P_USTRING: - push_utf8_allocate(&utf8_s1, *(char **)ptr); + push_utf8_allocate(&utf8_s1, *(char **)ptr, &converted_size); printf("<input type=text size=40 name=\"parm_%s\" value=\"%s\">", make_parm_name(parm->label), fix_quotes(ctx, utf8_s1)); SAFE_FREE(utf8_s1); @@ -897,6 +898,7 @@ static void shares_page(void) int i; int mode = 0; unsigned int parm_filter = FLAG_BASIC; + size_t converted_size; if (share) snum = lp_servicenumber(share); @@ -951,7 +953,7 @@ static void shares_page(void) for (i=0;i<lp_numservices();i++) { s = lp_servicename(i); if (s && (*s) && strcmp(s,"IPC$") && !lp_print_ok(i)) { - push_utf8_allocate(&utf8_s, s); + push_utf8_allocate(&utf8_s, s, &converted_size); printf("<option %s value=\"%s\">%s\n", (share && strcmp(share,s)==0)?"SELECTED":"", utf8_s, utf8_s); |