From 85d7691d959b7c23707d75b19bdfb2918bcfa01b Mon Sep 17 00:00:00 2001 From: Liviu Chircu Date: Mon, 28 Mar 2022 20:31:18 +0300 Subject: [PATCH] Improve previous commit * fix 2 regressions * optimize (merge) some HAVE() checks --- parser/case_call.h | 4 ++-- parser/case_cont.h | 4 +--- parser/case_max.h | 4 +--- parser/case_reco.h | 4 +--- parser/parse_hname2.c | 2 +- 5 files changed, 6 insertions(+), 12 deletions(-) diff --git a/parser/case_call.h b/parser/case_call.h index ac69d5d424f..4e8674c4eb3 100644 --- a/parser/case_call.h +++ b/parser/case_call.h @@ -31,8 +31,6 @@ #define ID_INF_CASE \ - if (!HAVE(4)) \ - goto other; \ switch(LOWER_DWORD(val)) { \ case __id1_: \ hdr->type = HDR_CALLID_T; \ @@ -59,6 +57,8 @@ #define call_CASE \ p += 4; \ + if (!HAVE(4)) \ + goto other; \ val = READ(p); \ ID_INF_CASE; \ goto other; diff --git a/parser/case_cont.h b/parser/case_cont.h index 8e1549334b8..99c0ed5809b 100644 --- a/parser/case_cont.h +++ b/parser/case_cont.h @@ -67,8 +67,6 @@ switch(LOWER_DWORD(val)) { \ case _osit_: \ p += 4; \ - if (!HAVE(4)) \ - goto other; \ val = READ(p); \ ion_CASE; \ goto other; \ @@ -91,7 +89,7 @@ goto dc_cont; \ case _disp_: \ p += 4; \ - if (!HAVE(4)) \ + if (!HAVE(8)) \ goto other; \ val = READ(p); \ DISPOSITION_CASE; \ diff --git a/parser/case_max.h b/parser/case_max.h index 8f1b43cca2c..52032ef6961 100644 --- a/parser/case_max.h +++ b/parser/case_max.h @@ -38,8 +38,6 @@ switch(LOWER_DWORD(val)) { \ case _forw_: \ p += 4; \ - if (!HAVE(4)) \ - goto other; \ val = READ(p); \ ARDS_CASE; \ goto other; \ @@ -48,7 +46,7 @@ #define max_CASE \ p += 4; \ - if (!HAVE(4)) \ + if (!HAVE(8)) \ goto other; \ val = READ(p); \ FORW_CASE; \ diff --git a/parser/case_reco.h b/parser/case_reco.h index f4bfc5a6202..510298e3f3d 100644 --- a/parser/case_reco.h +++ b/parser/case_reco.h @@ -38,8 +38,6 @@ switch(LOWER_DWORD(val)) { \ case _rd_r_: \ p += 4; \ - if (!HAVE(4)) \ - goto other; \ val = READ(p); \ OUTE_CASE; \ goto other; \ @@ -48,7 +46,7 @@ #define reco_CASE \ p += 4; \ - if (!HAVE(4)) \ + if (!HAVE(8)) \ goto other; \ val = READ(p); \ RD_R_CASE; \ diff --git a/parser/parse_hname2.c b/parser/parse_hname2.c index 0614d6866b3..4f003b110ce 100644 --- a/parser/parse_hname2.c +++ b/parser/parse_hname2.c @@ -109,7 +109,7 @@ static inline char* skip_ws(char* p, char *end) #ifdef FUZZ_BUILD /* fuzzers are sensible to heap read overflows, so enable all "HAVE" checks */ -#define HAVE(bytes) (end - p < (bytes)) +#define HAVE(bytes) (end - p >= (long)(bytes)) #else /* with PKG memory, parser read overflows of a few bytes are harmless, since * the memory is pre-allocated and the read cannot SIGSEGV, making the parser