]> The Tcpdump Group git mirrors - tcpdump/commitdiff
Fix the pointer tests in the non-ndoified TTEST2() macro as well. tcpdump-4.6
authorGuy Harris <[email protected]>
Mon, 2 Mar 2015 21:46:29 +0000 (13:46 -0800)
committerGuy Harris <[email protected]>
Wed, 20 May 2015 22:28:13 +0000 (15:28 -0700)
interface.h

index 299d010ea2791373878a5672e5a671947b0ac264..03463751856e43c6e49f4952bb5d2d710e87fcd7 100644 (file)
@@ -104,9 +104,21 @@ extern int32_t thiszone;   /* seconds offset from gmt to local time */
  * that "snapend - (l)" underflows.
  *
  * The check is for <= rather than < because "l" might be 0.
  * that "snapend - (l)" underflows.
  *
  * The check is for <= rather than < because "l" might be 0.
+ *
+ * We cast the pointers to uintptr_t to make sure that the compiler
+ * doesn't optimize away any of these tests (which it is allowed to
+ * do, as adding an integer to, or subtracting an integer from, a
+ * pointer assumes that the pointer is a pointer to an element of an
+ * array and that the result of the addition or subtraction yields a
+ * pointer to another member of the array, so that, for example, if
+ * you subtract a positive integer from a pointer, the result is
+ * guaranteed to be less than the original pointer value). See
+ *
+ *     http://www.kb.cert.org/vuls/id/162289
  */
  */
-#define TTEST2(var, l) (snapend - (l) <= snapend && \
-                       (const u_char *)&(var) <= snapend - (l))
+#define TTEST2(var, l) \
+       ((uintptr_t)snapend - (l) <= (uintptr_t)snapend && \
+          (uintptr_t)&(var) <= (uintptr_t)snapend - (l))
 
 /* True if "var" was captured */
 #define TTEST(var) TTEST2(var, sizeof(var))
 
 /* True if "var" was captured */
 #define TTEST(var) TTEST2(var, sizeof(var))