tcpdump mailing list archives

Re: GET_BYTES() macro, doing a bounds check and a memcpy()?


From: Francois-Xavier Le Bail <devel.fx.lebail () orange fr>
Date: Tue, 10 Sep 2019 19:29:46 +0200

On 03/05/2019 19:08, Guy Harris wrote:
Commit e150c713a2ea333e9ab173e062b447dd65c9a4ee added some ND_TCHECK_LEN() calls before doing a memcpy.

Should we have a function

      static inline void
      get_bytes(netdissect_options *ndo, u_char *dst, const u_char *p, size_t len)
      {
              if (!ND_TCHECK_LEN(p, len))
                      longjmp(ndo->ndo_truncated, 1);
              UNALIGNED_MEMCPY(dst, p, len);
      }

and a macro

      #define GET_BYTES(p, len) get_bytes(ndo, (const u_char *)(p), len)

(it uses UNALIGNED_MEMCPY() to handle cases where the compiler "helpfully" optimizes the copy under the assumption 
that the source is aligned on a 2-byte or 4-byte boundary, on a platform such as a SPARC-based machine where 
misaligned loads/stores cause a trap or, worse, some ARM-based machines where unaligned access isn't enabled).

Done with aeb4d52613e356e75d20d0f6549f89c88d100028 and 60ce4f61b7ff6116f09b59ca32e9342e8600b52e.

_______________________________________________
tcpdump-workers mailing list
tcpdump-workers () lists tcpdump org
https://lists.sandelman.ca/mailman/listinfo/tcpdump-workers

Current thread: