ndr: mark invalid pull ndr_flags as unlikely
authorDouglas Bagnall <douglas.bagnall@catalyst.net.nz>
Fri, 29 Dec 2023 02:27:08 +0000 (15:27 +1300)
committerJule Anger <janger@samba.org>
Mon, 12 Feb 2024 10:53:13 +0000 (10:53 +0000)
This might have little effect, but sometimes we see primatives like
ndr_pull_uint32() taking a few percent of the CPU time, and this is in
all those functions.

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
BUG: https://bugzilla.samba.org/show_bug.cgi?id=15574
(cherry picked from commit 4face258dee93dcd01dce71fcb7448b285ff4860)

librpc/ndr/libndr.h

index 70dd01e49a673038a14241979e3f9eb80f19eb9b..03d1aead01a622f1d6a234b834e104249b55d9a8 100644 (file)
@@ -367,7 +367,7 @@ enum ndr_compression_alg {
 };
 
 #define NDR_PULL_CHECK_FLAGS(ndr, ndr_flags) do { \
-       if ((ndr_flags) & ~(NDR_SCALARS|NDR_BUFFERS)) { \
+       if (unlikely((ndr_flags) & ~(NDR_SCALARS|NDR_BUFFERS))) { \
                return ndr_pull_error(ndr, NDR_ERR_FLAGS, "Invalid pull struct ndr_flags 0x%"PRI_NDR_FLAGS_TYPE, ndr_flags); \
        } \
 } while (0)