libcli/smb: add smb_buffer_oob() helper
authorStefan Metzmacher <metze@samba.org>
Wed, 26 Oct 2011 12:20:53 +0000 (14:20 +0200)
committerStefan Metzmacher <metze@samba.org>
Wed, 26 Oct 2011 13:33:30 +0000 (15:33 +0200)
A copy of trans_oob().

metze

libcli/smb/smb_util.h
libcli/smb/util.c

index b5a06524cb27fd4fec4fd4ae76487538980eca33..322ecb63973ab19f65d9750e548fc71574a6b80e 100644 (file)
@@ -23,3 +23,5 @@ char *attrib_string(TALLOC_CTX *mem_ctx, uint32_t attrib);
 uint32_t unix_perms_to_wire(mode_t perms);
 mode_t wire_perms_to_unix(uint32_t perms);
 mode_t unix_filetype_from_wire(uint32_t wire_type);
+
+bool smb_buffer_oob(uint32_t bufsize, uint32_t offset, uint32_t length);
index b8c3dc5e968def52029a00bdce6d42260e57ddf1..b02ae00d0d95f24105a7abc3702def68cc628a09 100644 (file)
@@ -163,3 +163,15 @@ mode_t unix_filetype_from_wire(uint32_t wire_type)
        }
 }
 
+bool smb_buffer_oob(uint32_t bufsize, uint32_t offset, uint32_t length)
+{
+       if ((offset + length < offset) || (offset + length < length)) {
+               /* wrap */
+               return true;
+       }
+       if ((offset > bufsize) || (offset + length > bufsize)) {
+               /* overflow */
+               return true;
+       }
+       return false;
+}