diff options
author | Jeremy Allison <jra@samba.org> | 2007-03-30 22:25:08 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 12:19:01 -0500 |
commit | 261c004d7bf85de945a1a3956c1d8f15075bc224 (patch) | |
tree | 3bacb2553161bece2fe06d3a6c29a0f4b82de97c /source3/lib/util.c | |
parent | b0bcb483697249123f92f5ac477c98b579135887 (diff) | |
download | samba-261c004d7bf85de945a1a3956c1d8f15075bc224.tar.gz samba-261c004d7bf85de945a1a3956c1d8f15075bc224.tar.bz2 samba-261c004d7bf85de945a1a3956c1d8f15075bc224.zip |
r22014: Make us pass RANDOMIPC test again :-(. This is an ugly check-in,
but I've no option.
Jeremy.
(This used to be commit c3a565081d70b209a4f9e6e8f1859bf7194a5f74)
Diffstat (limited to 'source3/lib/util.c')
-rw-r--r-- | source3/lib/util.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/source3/lib/util.c b/source3/lib/util.c index cf8d49c502..809071662d 100644 --- a/source3/lib/util.c +++ b/source3/lib/util.c @@ -3124,3 +3124,26 @@ int this_is_smp(void) return 0; #endif } + +/**************************************************************** + Return a safe offset into a buffer, or NULL. +****************************************************************/ + +char *get_safe_offset(const char *buf_base, size_t buf_len, char *ptr, size_t off) +{ + const char *end_base = buf_base + buf_len; + const char *end_ptr = ptr + off; + + if (!buf_base || !ptr) { + return NULL; + } + + if (end_base < buf_base || end_ptr < ptr) { + return NULL; /* wrap. */ + } + + if (end_ptr < end_base) { + return ptr; + } + return NULL; +} |