librpc/nbt: Avoid reading invalid member of union
commitedad945339f6401b2566efddd33f47195e2637c3
authorJoseph Sutton <josephsutton@catalyst.net.nz>
Wed, 5 Jul 2023 22:57:59 +0000 (6 10:57 +1200)
committerDouglas Bagnall <dbagnall@samba.org>
Fri, 7 Jul 2023 01:14:06 +0000 (7 01:14 +0000)
treeae40dbdf8e82536f040776c62a0be4293adf6234
parent47b6696dcdfe7c5cb6e58ac6586ba45d39c39cc6
librpc/nbt: Avoid reading invalid member of union

WACK packets use the ‘data’ member of the ‘nbt_rdata’ union, but they
claim to be a different type — NBT_QTYPE_NETBIOS — than would normally
be used with that union member. This means that if rr_type is equal to
NBT_QTYPE_NETBIOS, ndr_push_nbt_res_rec() has to guess which type the
structure really is by examining the data member. However, if the
structure is actually of a different type, that union member will not be
valid and accessing it will invoke undefined behaviour.

To fix this, eliminate all the guesswork and introduce a new type,
NBT_QTYPE_WACK, which can never appear on the wire, and which indicates
that although the ‘data’ union member should be used, the wire type is
actually NBT_QTYPE_NETBIOS.

This means that as far as NDR is concerned, the ‘netbios’ member of the
‘nbt_rdata’ union will consistently be used for all NBT_QTYPE_NETBIOS
structures; we shall no longer access the wrong member of the union.

Credit to OSS-Fuzz.

REF: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=38480

BUG: https://bugzilla.samba.org/show_bug.cgi?id=15019

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Autobuild-User(master): Douglas Bagnall <dbagnall@samba.org>
Autobuild-Date(master): Fri Jul  7 01:14:06 UTC 2023 on atb-devel-224
libcli/nbt/nbtname.c
librpc/idl/nbt.idl
source4/nbt_server/packet.c