diff options
author | Andrew Bartlett <abartlet@samba.org> | 2011-03-22 20:57:36 +1100 |
---|---|---|
committer | Andrew Bartlett <abartlet@samba.org> | 2011-03-23 12:49:39 +1100 |
commit | 1d22c3919d08b4d18a1d021a407a98cb1402d7d7 (patch) | |
tree | 6d3a53bb42ca0d1886ff135d41f6a67ae6173c9e | |
parent | 1923b78209aaa2aa926dedd19e6c97fb449c48c8 (diff) | |
download | samba-1d22c3919d08b4d18a1d021a407a98cb1402d7d7.tar.gz samba-1d22c3919d08b4d18a1d021a407a98cb1402d7d7.tar.bz2 samba-1d22c3919d08b4d18a1d021a407a98cb1402d7d7.zip |
s3-safe_str: Futher simplify the macros by removing indirection
Now that we don't need to pass in the function name and string,
another level of indirection can be safely removed, and the operation
of these macros made much clearer.
Andrew Bartlett
-rw-r--r-- | source3/include/proto.h | 18 | ||||
-rw-r--r-- | source3/include/safe_string.h | 58 | ||||
-rw-r--r-- | source3/lib/util_str.c | 10 | ||||
-rw-r--r-- | source3/libsmb/clistr.c | 26 |
4 files changed, 41 insertions, 71 deletions
diff --git a/source3/include/proto.h b/source3/include/proto.h index d806b36dd2..0f313d637e 100644 --- a/source3/include/proto.h +++ b/source3/include/proto.h @@ -1352,11 +1352,11 @@ char *safe_strcpy_fn(char *dest, char *safe_strcat_fn(char *dest, const char *src, size_t maxlength); -char *alpha_strcpy_fn(char *dest, +char *alpha_strcpy(char *dest, const char *src, const char *other_safe_chars, size_t maxlength); -char *StrnCpy_fn(char *dest,const char *src,size_t n); +char *StrnCpy(char *dest,const char *src,size_t n); bool in_list(const char *s, const char *list, bool casesensitive); void string_free(char **s); bool string_set(char **dest,const char *src); @@ -2328,13 +2328,13 @@ size_t clistr_pull_fn(const char *inbuf, int dest_len, int src_len, int flags); -size_t clistr_pull_talloc_fn(TALLOC_CTX *ctx, - const char *base, - uint16_t flags2, - char **pp_dest, - const void *src, - int src_len, - int flags); +size_t clistr_pull_talloc(TALLOC_CTX *ctx, + const char *base, + uint16_t flags2, + char **pp_dest, + const void *src, + int src_len, + int flags); size_t clistr_align_out(struct cli_state *cli, const void *p, int flags); /* The following definitions come from libsmb/clitrans.c */ diff --git a/source3/include/safe_string.h b/source3/include/safe_string.h index f54464e9c0..a4648b57d4 100644 --- a/source3/include/safe_string.h +++ b/source3/include/safe_string.h @@ -105,84 +105,54 @@ size_t __unsafe_string_function_usage_here_char__(void); #define overmalloc_safe_strcpy(dest,src,maxlength) \ safe_strcpy_fn(dest,src,maxlength) -#define safe_strcpy(dest,src,maxlength) \ - safe_strcpy_fn2(dest,src,maxlength) - -#define safe_strcat(dest,src,maxlength) \ - safe_strcat_fn2(dest,src,maxlength) - -#define push_string_check(dest, src, dest_len, flags) \ - push_string_check_fn2(dest, src, dest_len, flags) - -#define pull_string_talloc(ctx, base_ptr, smb_flags2, dest, src, src_len, flags) \ - pull_string_talloc_fn2(ctx, base_ptr, smb_flags2, dest, src, src_len, flags) - -#define clistr_push(cli, dest, src, dest_len, flags) \ - clistr_push_fn2(cli, dest, src, dest_len, flags) - -#define clistr_pull(inbuf, dest, src, dest_len, src_len, flags) \ - clistr_pull_fn2(inbuf, dest, src, dest_len, src_len, flags) - -#define clistr_pull_talloc(ctx, base, flags2, pp_dest, src, src_len, flags) \ - clistr_pull_talloc_fn(ctx, base, flags2, pp_dest, src, src_len, flags) - -#define srvstr_push(base_ptr, smb_flags2, dest, src, dest_len, flags) \ - srvstr_push_fn2(base_ptr, smb_flags2, dest, src, dest_len, flags) - -#define alpha_strcpy(dest,src,other_safe_chars,maxlength) \ - alpha_strcpy_fn(dest,src,other_safe_chars,maxlength) - -#define StrnCpy(dest,src,n) \ - StrnCpy_fn(dest,src,n) - #ifdef HAVE_COMPILER_WILL_OPTIMIZE_OUT_FNS /* if the compiler will optimize out function calls, then use this to tell if we are have the correct types (this works only where sizeof() returns the size of the buffer, not the size of the pointer). */ -#define safe_strcpy_fn2(d, s, max_len) \ +#define safe_strcpy(d, s, max_len) \ (CHECK_STRING_SIZE(d, max_len+1) \ ? __unsafe_string_function_usage_here__() \ : safe_strcpy_fn((d), (s), (max_len))) -#define safe_strcat_fn2(d, s, max_len) \ +#define safe_strcat(d, s, max_len) \ (CHECK_STRING_SIZE(d, max_len+1) \ ? __unsafe_string_function_usage_here__() \ : safe_strcat_fn((d), (s), (max_len))) -#define push_string_check_fn2(dest, src, dest_len, flags) \ +#define push_string_check(dest, src, dest_len, flags) \ (CHECK_STRING_SIZE(dest, dest_len) \ ? __unsafe_string_function_usage_here_size_t__() \ : push_string_check_fn(dest, src, dest_len, flags)) -#define pull_string_talloc_fn2(ctx, base_ptr, smb_flags2, dest, src, src_len, flags) \ +#define pull_string_talloc(ctx, base_ptr, smb_flags2, dest, src, src_len, flags) \ pull_string_talloc_fn(ctx, base_ptr, smb_flags2, dest, src, src_len, flags) -#define clistr_push_fn2(cli, dest, src, dest_len, flags) \ +#define clistr_push(cli, dest, src, dest_len, flags) \ (CHECK_STRING_SIZE(dest, dest_len) \ ? __unsafe_string_function_usage_here_size_t__() \ : clistr_push_fn(cli, dest, src, dest_len, flags)) -#define clistr_pull_fn2(inbuf, dest, src, dest_len, srclen, flags) \ +#define clistr_pull(inbuf, dest, src, dest_len, srclen, flags) \ (CHECK_STRING_SIZE(dest, dest_len) \ ? __unsafe_string_function_usage_here_size_t__() \ : clistr_pull_fn(inbuf, dest, src, dest_len, srclen, flags)) -#define srvstr_push_fn2(base_ptr, smb_flags2, dest, src, dest_len, flags) \ +#define srvstr_push(base_ptr, smb_flags2, dest, src, dest_len, flags) \ (CHECK_STRING_SIZE(dest, dest_len) \ ? __unsafe_string_function_usage_here_size_t__() \ : srvstr_push_fn(base_ptr, smb_flags2, dest, src, dest_len, flags)) #else -#define safe_strcpy_fn2 safe_strcpy_fn -#define safe_strcat_fn2 safe_strcat_fn -#define push_string_check_fn2 push_string_check_fn -#define pull_string_talloc_fn2 pull_string_talloc_fn -#define clistr_push_fn2 clistr_push_fn -#define clistr_pull_fn2 clistr_pull_fn -#define srvstr_push_fn2 srvstr_push_fn +#define safe_strcpy safe_strcpy_fn +#define safe_strcat safe_strcat_fn +#define push_string_check push_string_check_fn +#define pull_string_talloc pull_string_talloc_fn +#define clistr_push clistr_push_fn +#define clistr_pull clistr_pull_fn +#define srvstr_push srvstr_push_fn #endif diff --git a/source3/lib/util_str.c b/source3/lib/util_str.c index a1dfc70707..f14d7dea92 100644 --- a/source3/lib/util_str.c +++ b/source3/lib/util_str.c @@ -573,10 +573,10 @@ char *safe_strcat_fn(char *dest, characters. Don't change it ! **/ -char *alpha_strcpy_fn(char *dest, - const char *src, - const char *other_safe_chars, - size_t maxlength) +char *alpha_strcpy(char *dest, + const char *src, + const char *other_safe_chars, + size_t maxlength) { size_t len, i; @@ -614,7 +614,7 @@ char *alpha_strcpy_fn(char *dest, Like strncpy but always null terminates. Make sure there is room! The variable n should always be one less than the available size. **/ -char *StrnCpy_fn(char *dest,const char *src,size_t n) +char *StrnCpy(char *dest,const char *src,size_t n) { char *d = dest; diff --git a/source3/libsmb/clistr.c b/source3/libsmb/clistr.c index 8856e03dd0..373cce590d 100644 --- a/source3/libsmb/clistr.c +++ b/source3/libsmb/clistr.c @@ -58,21 +58,21 @@ size_t clistr_pull_fn(const char *inbuf, src_len, flags); } -size_t clistr_pull_talloc_fn(TALLOC_CTX *ctx, - const char *base, - uint16_t flags2, - char **pp_dest, - const void *src, - int src_len, - int flags) +size_t clistr_pull_talloc(TALLOC_CTX *ctx, + const char *base, + uint16_t flags2, + char **pp_dest, + const void *src, + int src_len, + int flags) { return pull_string_talloc_fn(ctx, - base, - flags2, - pp_dest, - src, - src_len, - flags); + base, + flags2, + pp_dest, + src, + src_len, + flags); } size_t clistr_align_out(struct cli_state *cli, const void *p, int flags) |