summaryrefslogtreecommitdiff
path: root/source3/include
diff options
context:
space:
mode:
authorAndrew Bartlett <abartlet@samba.org>2011-03-22 21:03:59 +1100
committerAndrew Bartlett <abartlet@samba.org>2011-03-23 03:39:35 +0100
commitd73db405f71002deaddeea68adb747ef1984945c (patch)
tree0465e3a6936f1900886046ab55cf5fd63dcc0c0f /source3/include
parent1d22c3919d08b4d18a1d021a407a98cb1402d7d7 (diff)
downloadsamba-d73db405f71002deaddeea68adb747ef1984945c.tar.gz
samba-d73db405f71002deaddeea68adb747ef1984945c.tar.bz2
samba-d73db405f71002deaddeea68adb747ef1984945c.zip
s3-safe_string: Add checked_strlcpy()
This is strlcpy, just with an extra check of the parameters with sizeof(), use only where that works. Andrew Bartlett Autobuild-User: Andrew Bartlett <abartlet@samba.org> Autobuild-Date: Wed Mar 23 03:39:35 CET 2011 on sn-devel-104
Diffstat (limited to 'source3/include')
-rw-r--r--source3/include/safe_string.h12
1 files changed, 12 insertions, 0 deletions
diff --git a/source3/include/safe_string.h b/source3/include/safe_string.h
index a4648b57d4..611f850d12 100644
--- a/source3/include/safe_string.h
+++ b/source3/include/safe_string.h
@@ -144,6 +144,17 @@ size_t __unsafe_string_function_usage_here_char__(void);
? __unsafe_string_function_usage_here_size_t__() \
: srvstr_push_fn(base_ptr, smb_flags2, dest, src, dest_len, flags))
+/* This allows the developer to choose to check the arguments to
+ strlcpy. if the compiler will optimize out function calls, then
+ use this to tell if we are have the correct size buffer (this works only
+ where sizeof() returns the size of the buffer, not the size of the
+ pointer), so stack and static variables only */
+
+#define checked_strlcpy(dest, src, size) \
+ (sizeof(dest) != (size) \
+ ? __unsafe_string_function_usage_here_size_t__() \
+ : strlcpy(dest, src, size))
+
#else
#define safe_strcpy safe_strcpy_fn
@@ -153,6 +164,7 @@ size_t __unsafe_string_function_usage_here_char__(void);
#define clistr_push clistr_push_fn
#define clistr_pull clistr_pull_fn
#define srvstr_push srvstr_push_fn
+#define checked_strlcpy strlcpy
#endif