]> The Tcpdump Group git mirrors - tcpdump/commitdiff
Add GET_CPY_BYTES() macro and get_cpy_bytes() function
authorFrancois-Xavier Le Bail <[email protected]>
Mon, 9 Sep 2019 17:58:36 +0000 (19:58 +0200)
committerFrancois-Xavier Le Bail <[email protected]>
Mon, 9 Sep 2019 17:59:21 +0000 (19:59 +0200)
With setjmp/longjmp logic to call the UNALIGNED_MEMCPY() macro
after bounds checking.

The macro must be used with a packet buffer pointer as second parameter.

extract.h

index 007e9dbb57e805f3a775f270d0c4afc87bbc9fc0..3d3deb857392532acc9a84d8c6d7bf3dd3a6a232 100644 (file)
--- a/extract.h
+++ b/extract.h
@@ -855,6 +855,14 @@ get_ipv4_to_network_order(netdissect_options *ndo, const u_char *p)
        return EXTRACT_IPV4_TO_NETWORK_ORDER(p);
 }
 
+static inline void
+get_cpy_bytes(netdissect_options *ndo, u_char *dst, const u_char *p, size_t len)
+{
+       if (!ND_TTEST_LEN(p, len))
+               longjmp(ndo->ndo_truncated, 1);
+       UNALIGNED_MEMCPY(dst, p, len);
+}
+
 #define GET_U_1(p) get_u_1(ndo, (const u_char *)(p))
 #define GET_S_1(p) get_s_1(ndo, (const u_char *)(p))
 
@@ -896,4 +904,6 @@ get_ipv4_to_network_order(netdissect_options *ndo, const u_char *p)
 #define GET_IPV4_TO_HOST_ORDER(p) get_ipv4_to_host_order(ndo, (const u_char *)(p))
 #define GET_IPV4_TO_NETWORK_ORDER(p) get_ipv4_to_network_order(ndo, (const u_char *)(p))
 
+#define GET_CPY_BYTES(dst, p, len) get_cpy_bytes(ndo, (u_char *)(dst), (const u_char *)(p), len)
+
 #endif /* EXTRACT_H */