summaryrefslogtreecommitdiffstats
path: root/tests/fuzzer.c
diff options
context:
space:
mode:
authorYann Collet <cyan@fb.com>2016-11-17 21:02:06 (GMT)
committerYann Collet <cyan@fb.com>2016-11-17 21:02:06 (GMT)
commit1abecbc33c8ec5b84d2623dcbe73136aeb99db37 (patch)
tree398361394772160cd31cbc2b496d4814484fcb10 /tests/fuzzer.c
parent7fde7438d39f8452f89e3fee5ba4a16c502dffb0 (diff)
downloadlz4-1abecbc33c8ec5b84d2623dcbe73136aeb99db37.zip
lz4-1abecbc33c8ec5b84d2623dcbe73136aeb99db37.tar.gz
lz4-1abecbc33c8ec5b84d2623dcbe73136aeb99db37.tar.bz2
fix 32-bits mode.
Large File support for Mac OS-X in 32-bits mode Fixed potential undefined behavior Changed makefile for 32-bits mode
Diffstat (limited to 'tests/fuzzer.c')
-rw-r--r--tests/fuzzer.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/tests/fuzzer.c b/tests/fuzzer.c
index 301b01a..06cfd40 100644
--- a/tests/fuzzer.c
+++ b/tests/fuzzer.c
@@ -170,7 +170,7 @@ static void FUZ_fillCompressibleNoiseBuffer(void* buffer, size_t bufferSize, dou
static int FUZ_AddressOverflow(void)
{
char* buffers[MAX_NB_BUFF_I134+1];
- int i, nbBuff=0;
+ int nbBuff=0;
int highAddress = 0;
DISPLAY("Overflow tests : ");
@@ -185,12 +185,13 @@ static int FUZ_AddressOverflow(void)
buffers[0] = (char*)malloc(BLOCKSIZE_I134);
buffers[1] = (char*)malloc(BLOCKSIZE_I134);
if ((!buffers[0]) || (!buffers[1])) {
+ free(buffers[0]); free(buffers[1]);
DISPLAY("not enough memory for tests \n");
return 0;
}
for (nbBuff=2; nbBuff < MAX_NB_BUFF_I134; nbBuff++) {
- DISPLAY("%3i \b\b\b\b", nbBuff);
+ DISPLAY("%3i \b\b\b\b", nbBuff); fflush(stdout);
buffers[nbBuff] = (char*)malloc(BLOCKSIZE_I134);
if (buffers[nbBuff]==NULL) goto _endOfTests;
@@ -201,7 +202,7 @@ static int FUZ_AddressOverflow(void)
}
{ size_t const sizeToGenerateOverflow = (size_t)(- ((uintptr_t)buffers[nbBuff-1]) + 512);
- int const nbOf255 = (int)((sizeToGenerateOverflow / 255) + 1);
+ unsigned const nbOf255 = (unsigned)((sizeToGenerateOverflow / 255) + 1);
char* const input = buffers[nbBuff-1];
char* output = buffers[nbBuff];
int r;
@@ -209,15 +210,15 @@ static int FUZ_AddressOverflow(void)
input[1] = (char)0xFF;
input[2] = (char)0xFF;
input[3] = (char)0xFF;
- for(i = 4; i <= nbOf255+4; i++) input[i] = (char)0xff;
+ { unsigned u; for(u = 4; u <= nbOf255+4; u++) input[u] = (char)0xff; }
r = LZ4_decompress_safe(input, output, nbOf255+64, BLOCKSIZE_I134);
- if (r>0) goto _overflowError;
+ if (r>0) { DISPLAY("LZ4_decompress_safe = %i \n", r); goto _overflowError; }
input[0] = (char)0x1F; /* Match length overflow */
input[1] = (char)0x01;
input[2] = (char)0x01;
input[3] = (char)0x00;
r = LZ4_decompress_safe(input, output, nbOf255+64, BLOCKSIZE_I134);
- if (r>0) goto _overflowError;
+ if (r>0) { DISPLAY("LZ4_decompress_safe = %i \n", r); goto _overflowError; }
output = buffers[nbBuff-2]; /* Reverse in/out pointer order */
input[0] = (char)0xF0; /* Literal length overflow */
@@ -237,7 +238,7 @@ static int FUZ_AddressOverflow(void)
nbBuff++;
_endOfTests:
- for (i=0 ; i<nbBuff; i++) free(buffers[i]);
+ { int i; for (i=0 ; i<nbBuff; i++) free(buffers[i]); }
if (!highAddress) DISPLAY("high address not possible \n");
else DISPLAY("all overflows correctly detected \n");
return 0;