diff --git a/src/filter/cto.h b/src/filter/cto.h index 3c15d224..daa80534 100644 --- a/src/filter/cto.h +++ b/src/filter/cto.h @@ -58,10 +58,18 @@ static int F(Filter *f) // must not conflict with the mark. // Note that unsigned comparison checks both edges of buffer. for (ic = 0; ic < size - 5; ic++) - if (COND(b,ic) && get_le32(b+ic+1)+ic+1 >= size) + { + if (!COND(b,ic)) + continue; + jc = get_le32(b+ic+1)+ic+1; + if (jc < size) { - buf[b[ic+1]] |= 1; + if (jc + addvalue >= (1u << 24)) // hi 8 bits won't be cto8 + return -1; } + else + buf[b[ic+1]] |= 1; + } if (getcto(f, buf) < 0) return -1; @@ -79,8 +87,7 @@ static int F(Filter *f) // try to detect 'real' calls only if (jc < size) { - if ((1u<<24)<=(jc+addvalue)) // hi 8 bits won't be cto8 - return 1; // fail - buffer not restored + assert(jc + addvalue < (1u << 24)); // hi 8 bits won't be cto8 #ifdef U set_be32(b+ic+1,jc+addvalue+cto); #endif diff --git a/src/filter/ctoj.h b/src/filter/ctoj.h index 25ac5ad4..1fde538f 100644 --- a/src/filter/ctoj.h +++ b/src/filter/ctoj.h @@ -57,10 +57,18 @@ static int F(Filter *f) memset(buf,0,256); for (ic = 0; ic < size - 5; ic++) - if (COND(b,ic,lastcall) && get_le32(b+ic+1)+ic+1 >= size) + { + if (!COND(b,ic,lastcall)) + continue; + jc = get_le32(b+ic+1)+ic+1; + if (jc < size) { - buf[b[ic+1]] |= 1; + if (jc + addvalue >= (1u << 24)) // hi 8 bits won't be cto8 + return -1; } + else + buf[b[ic+1]] |= 1; + } if (getcto(f, buf) < 0) return -1; @@ -78,8 +86,7 @@ static int F(Filter *f) // try to detect 'real' calls only if (jc < size) { - if ((1u<<24)<=(jc+addvalue)) // hi 8 bits won't be cto8 - return 1; // fail - buffer not restored + assert(jc + addvalue < (1u << 24)); // hi 8 bits won't be cto8 #ifdef U set_be32(b+ic+1,jc+addvalue+cto); #endif diff --git a/src/filter/ctok.h b/src/filter/ctok.h index 202c4b84..e91d6a29 100644 --- a/src/filter/ctok.h +++ b/src/filter/ctok.h @@ -58,10 +58,18 @@ static int F(Filter *f) memset(buf,0,256); for (ic = 0; ic < size - 5; ic++) - if (COND(b,ic,lastcall,id) && get_le32(b+ic+1)+ic+1 >= size) + { + if (!COND(b,ic,lastcall,id)) + continue; + jc = get_le32(b+ic+1)+ic+1; + if (jc < size) { - buf[b[ic+1]] |= 1; + if (jc + addvalue >= (1u << 24)) // hi 8 bits won't be cto8 + return -1; } + else + buf[b[ic+1]] |= 1; + } if (getcto(f, buf) < 0) return -1; @@ -79,8 +87,7 @@ static int F(Filter *f) // try to detect 'real' calls only if (jc < size) { - if ((1u<<24)<=(jc+addvalue)) // hi 8 bits won't be cto8 - return 1; // fail - buffer not restored + assert(jc + addvalue < (1u << 24)); // hi 8 bits won't be cto8 #ifdef U set_be32(b+ic+1,jc+addvalue+cto); #endif diff --git a/src/filteri.cpp b/src/filteri.cpp index 3f15cf75..2f50031a 100644 --- a/src/filteri.cpp +++ b/src/filteri.cpp @@ -109,7 +109,7 @@ umin(unsigned const a, unsigned const b) #define COND1(b,x) (b[x] == 0xe8 || b[x] == 0xe9) #define COND2(b,x,lc) (lc!=(x) && 0xf==b[(x)-1] && 0x80<=b[x] && b[x]<=0x8f) -#define COND(b,x,lc,id) (COND1(b,x) || ((9<=(0xf&(id))) && COND2(b,x,lc))) +#define COND(b,x,lc,id) (COND1(b,x) || ((9<=(0xf&(id))) && COND2(b,x,lc))) #define F f_ctok32_e8e9_bswap_le #define U u_ctok32_e8e9_bswap_le #include "filter/ctok.h"