Skip to content

Commit 73a2e1f

Browse files
committed
Fix the pointer tests in the non-ndoified TTEST2() macro as well.
1 parent ce0e22c commit 73a2e1f

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

interface.h

+14-2
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,21 @@ extern int32_t thiszone; /* seconds offset from gmt to local time */
117117
* that "snapend - (l)" underflows.
118118
*
119119
* The check is for <= rather than < because "l" might be 0.
120+
*
121+
* We cast the pointers to uintptr_t to make sure that the compiler
122+
* doesn't optimize away any of these tests (which it is allowed to
123+
* do, as adding an integer to, or subtracting an integer from, a
124+
* pointer assumes that the pointer is a pointer to an element of an
125+
* array and that the result of the addition or subtraction yields a
126+
* pointer to another member of the array, so that, for example, if
127+
* you subtract a positive integer from a pointer, the result is
128+
* guaranteed to be less than the original pointer value). See
129+
*
130+
* http://www.kb.cert.org/vuls/id/162289
120131
*/
121-
#define TTEST2(var, l) (snapend - (l) <= snapend && \
122-
(const u_char *)&(var) <= snapend - (l))
132+
#define TTEST2(var, l) \
133+
((uintptr_t)snapend - (l) <= (uintptr_t)snapend && \
134+
(uintptr_t)&(var) <= (uintptr_t)snapend - (l))
123135

124136
/* True if "var" was captured */
125137
#define TTEST(var) TTEST2(var, sizeof(var))

0 commit comments

Comments
 (0)