]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
nmblib: avoid undefined behaviour in handle_name_ptrs()
authorDouglas Bagnall <douglas.bagnall@catalyst.net.nz>
Sun, 19 Jan 2020 02:08:58 +0000 (15:08 +1300)
committerAndrew Bartlett <abartlet@samba.org>
Fri, 7 Feb 2020 10:19:39 +0000 (10:19 +0000)
If *offset is length - 1, we would read ubuf[(*offset)+1] as the lower
bits of the new *offset. This value is undefined, but because it is
checked against the valid range, there is no way to read further
beyond that one byte.

Credit to oss-fuzz.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=14242
OSS-Fuzz: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=20193

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Autobuild-User(master): Andrew Bartlett <abartlet@samba.org>
Autobuild-Date(master): Fri Feb  7 10:19:39 UTC 2020 on sn-devel-184

source3/libsmb/nmblib.c

index 84cbb054b8eb4eec1688e406c06e74175c2b0131..c05fac2bba96bab3d8227347ae15da34a9a68f2e 100644 (file)
@@ -160,6 +160,9 @@ static bool handle_name_ptrs(unsigned char *ubuf,int *offset,int length,
                if (!*got_pointer)
                        (*ret) += 2;
                (*got_pointer)=True;
+               if (*offset > length - 2) {
+                       return False;
+               }
                (*offset) = ((ubuf[*offset] & ~0xC0)<<8) | ubuf[(*offset)+1];
                if (loop_count++ == 10 ||
                                (*offset) < 0 || (*offset)>(length-2)) {