Fix issues with error handling.
Add new tests for out of range values and corrupted file.
This commit is contained in:
parent
bdf16c4cb9
commit
d250322490
4 changed files with 111 additions and 9 deletions
|
@ -190,6 +190,10 @@ deserialize_checksum(uchar_t *checksum, uchar_t *buf, int cksum_bytes)
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Perform keyed hashing. With Skein, HMAC is not used, rather Skein's
|
||||
* native MAC is used which is more optimal than HMAC.
|
||||
*/
|
||||
int
|
||||
hmac_init(mac_ctx_t *mctx, int cksum, crypto_ctx_t *cctx)
|
||||
{
|
||||
|
|
24
main.c
24
main.c
|
@ -524,7 +524,7 @@ cont:
|
|||
*/
|
||||
#define UNCOMP_BAIL err = 1; goto uncomp_done
|
||||
|
||||
static void
|
||||
static int
|
||||
start_decompress(const char *filename, const char *to_filename)
|
||||
{
|
||||
char tmpfile[MAXPATHLEN];
|
||||
|
@ -543,6 +543,7 @@ start_decompress(const char *filename, const char *to_filename)
|
|||
err = 0;
|
||||
flags = 0;
|
||||
thread = 0;
|
||||
dary = NULL;
|
||||
init_algo_props(&props);
|
||||
|
||||
/*
|
||||
|
@ -555,7 +556,7 @@ start_decompress(const char *filename, const char *to_filename)
|
|||
if (fstat(compfd, &sbuf) == -1)
|
||||
err_exit(1, "Cannot stat: %s", filename);
|
||||
if (sbuf.st_size == 0)
|
||||
return;
|
||||
return (1);
|
||||
|
||||
if ((uncompfd = open(to_filename, O_WRONLY|O_CREAT|O_TRUNC, 0)) == -1) {
|
||||
close(compfd);
|
||||
|
@ -1050,6 +1051,8 @@ uncomp_done:
|
|||
|
||||
if (!hide_cmp_stats) show_compression_stats(chunksize);
|
||||
slab_cleanup(hide_mem_stats);
|
||||
|
||||
return (err);
|
||||
}
|
||||
|
||||
static void *
|
||||
|
@ -1201,7 +1204,7 @@ plain_compress:
|
|||
main_cancel = 1;
|
||||
tdat->len_cmp = 0;
|
||||
sem_post(&tdat->cmp_done_sem);
|
||||
return;
|
||||
return (0);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1327,7 +1330,7 @@ do_cancel:
|
|||
*/
|
||||
#define COMP_BAIL err = 1; goto comp_done
|
||||
|
||||
void
|
||||
static int
|
||||
start_compress(const char *filename, uint64_t chunksize, int level)
|
||||
{
|
||||
struct wdata w;
|
||||
|
@ -1434,6 +1437,7 @@ start_compress(const char *filename, uint64_t chunksize, int level)
|
|||
err = 0;
|
||||
thread = 0;
|
||||
single_chunk = 0;
|
||||
rctx = NULL;
|
||||
slab_cache_add(chunksize);
|
||||
slab_cache_add(compressed_chunksize);
|
||||
slab_cache_add(sizeof (struct cmp_data));
|
||||
|
@ -1461,7 +1465,7 @@ start_compress(const char *filename, uint64_t chunksize, int level)
|
|||
|
||||
if (sbuf.st_size == 0) {
|
||||
close(uncompfd);
|
||||
return;
|
||||
return (1);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -1875,6 +1879,8 @@ comp_done:
|
|||
if (!hide_cmp_stats) show_compression_stats(chunksize);
|
||||
_stats_func(!hide_cmp_stats);
|
||||
slab_cleanup(hide_mem_stats);
|
||||
|
||||
return (err);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -1996,7 +2002,7 @@ main(int argc, char *argv[])
|
|||
char *filename = NULL;
|
||||
char *to_filename = NULL;
|
||||
ssize_t chunksize = DEFAULT_CHUNKSIZE;
|
||||
int opt, level, num_rem;
|
||||
int opt, level, num_rem, err;
|
||||
|
||||
exec_name = get_execname(argv[0]);
|
||||
level = 6;
|
||||
|
@ -2210,13 +2216,13 @@ main(int argc, char *argv[])
|
|||
* Start the main routines.
|
||||
*/
|
||||
if (do_compress)
|
||||
start_compress(filename, chunksize, level);
|
||||
err = start_compress(filename, chunksize, level);
|
||||
else if (do_uncompress)
|
||||
start_decompress(filename, to_filename);
|
||||
err = start_decompress(filename, to_filename);
|
||||
|
||||
if (pwd_file)
|
||||
free(pwd_file);
|
||||
free(filename);
|
||||
free((void *)exec_name);
|
||||
return (0);
|
||||
return (err);
|
||||
}
|
||||
|
|
|
@ -177,6 +177,7 @@ create_dedupe_context(uint64_t chunksize, uint64_t real_chunksize, int rab_blk_s
|
|||
ctx = (dedupe_context_t *)slab_alloc(NULL, sizeof (dedupe_context_t));
|
||||
ctx->rabin_poly_max_block_size = RAB_POLYNOMIAL_MAX_BLOCK_SIZE;
|
||||
|
||||
ctx->current_window_data = NULL;
|
||||
ctx->fixed_flag = fixed_flag;
|
||||
ctx->rabin_break_patt = 0;
|
||||
ctx->rabin_poly_avg_block_size = RAB_BLK_AVG_SZ(rab_blk_sz);
|
||||
|
|
91
test/t9.tst
Normal file
91
test/t9.tst
Normal file
|
@ -0,0 +1,91 @@
|
|||
#
|
||||
# Out of range parameters
|
||||
#
|
||||
echo "#################################################"
|
||||
echo "# Test out of range parameters"
|
||||
echo "#################################################"
|
||||
|
||||
for feat in "-L" "-L -D" "-L -D -E" "-L -B5" "-L -D -E -B2" "-F" "-F -L"
|
||||
do
|
||||
cmd="../../pcompress -c dummy -l4 -s1m $feat combined.dat"
|
||||
echo "Running $cmd"
|
||||
eval $cmd
|
||||
if [ $? -eq 0 ]
|
||||
then
|
||||
echo "${cmd} DID NOT ERROR where expected"
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
|
||||
for feat in "-B8 -s2m -l1" "-B0 -s2m -l1" "-D -s10k -l1" "-D -F -s2m -l1" "-p -e -s2m -l1" "-s2m -l15"
|
||||
do
|
||||
for algo in lzfx lz4 zlib bzip2 libbsc ppmd lzma
|
||||
do
|
||||
cmd="../../pcompress -c lzfx $feat combined.dat"
|
||||
echo "Running $cmd"
|
||||
eval $cmd
|
||||
if [ $? -eq 0 ]
|
||||
then
|
||||
echo "${cmd} DID NOT ERROR where expected"
|
||||
rm -f combined.dat.pz
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
done
|
||||
|
||||
for feat in "-S CRC64" "-S SKEIN256" "-S SKEIN512" "-S SHA256" "-S SHA512"
|
||||
do
|
||||
rm -f combined.dat.pz
|
||||
rm -f combined.dat.1
|
||||
|
||||
cmd="../../pcompress -c lzfx -l3 -s1m $feat combined.dat"
|
||||
echo "Running $cmd"
|
||||
eval $cmd
|
||||
if [ $? -ne 0 ]
|
||||
then
|
||||
echo "${cmd} errored."
|
||||
rm -f combined.dat.pz
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Corrupting file header ..."
|
||||
dd if=/dev/urandom of=combined.dat.pz bs=4 seek=1 count=1
|
||||
cmd="../../pcompress -d combined.dat.pz combined.dat.1"
|
||||
eval $cmd
|
||||
if [ $? -eq 0 ]
|
||||
then
|
||||
echo "${cmd} DID NOT ERROR where expected."
|
||||
rm -f combined.dat.pz
|
||||
rm -f combined.dat.1
|
||||
exit 1
|
||||
fi
|
||||
|
||||
rm -f combined.dat.pz
|
||||
rm -f combined.dat.1
|
||||
|
||||
cmd="../../pcompress -c zlib -l3 -s1m $feat combined.dat"
|
||||
echo "Running $cmd"
|
||||
eval $cmd
|
||||
if [ $? -ne 0 ]
|
||||
then
|
||||
echo "${cmd} errored."
|
||||
rm -f combined.dat.pz
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Corrupting file ..."
|
||||
dd if=/dev/urandom of=combined.dat.pz bs=4 seek=100 count=1
|
||||
cmd="../../pcompress -d combined.dat.pz combined.dat.1"
|
||||
eval $cmd
|
||||
if [ $? -eq 0 ]
|
||||
then
|
||||
echo "${cmd} DID NOT ERROR where expected."
|
||||
rm -f combined.dat.pz
|
||||
rm -f combined.dat.1
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
|
||||
echo "#################################################"
|
||||
echo ""
|
||||
|
Loading…
Reference in a new issue