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 /source3/lib | |
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)
Diffstat (limited to 'source3/lib')
-rw-r--r-- | source3/lib/charcnv.c | 267 | ||||
-rw-r--r-- | source3/lib/ms_fnmatch.c | 5 | ||||
-rw-r--r-- | source3/lib/smbldap.c | 27 | ||||
-rw-r--r-- | source3/lib/util_reg_api.c | 36 | ||||
-rw-r--r-- | source3/lib/util_str.c | 52 | ||||
-rw-r--r-- | source3/lib/util_unistr.c | 20 |
6 files changed, 221 insertions, 186 deletions
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; } /******************************************************************* |