mirror of
https://github.com/intel/isa-l.git
synced 2025-02-21 06:37:40 +01:00
igzip: Modify igzip_cli to abort when in_file is out_file
Change-Id: Iccb1926e6eb4461ff9f02ab6d593689e96e94155 Signed-off-by: Roy Oursler <roy.j.oursler@intel.com>
This commit is contained in:
parent
1fdc5941a3
commit
6f3599c191
@ -1,5 +1,5 @@
|
||||
.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.47.6.
|
||||
.TH IGZIP "1" "September 2018" "igzip command line interface 2.24.0" "User Commands"
|
||||
.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.47.7.
|
||||
.TH IGZIP "1" "November 2018" "igzip command line interface 2.24.0" "User Commands"
|
||||
.SH NAME
|
||||
igzip \- compress or decompress files similar to gzip
|
||||
.SH SYNOPSIS
|
||||
|
@ -364,20 +364,18 @@ size_t fwrite_safe(void *buf, size_t word_size, size_t buf_size, FILE * out, cha
|
||||
return write_size;
|
||||
}
|
||||
|
||||
void open_files(FILE ** in, FILE ** out, char *infile_name, size_t infile_name_len,
|
||||
char *outfile_name)
|
||||
void open_in_file(FILE ** in, char *infile_name)
|
||||
{
|
||||
*in = NULL;
|
||||
*out = NULL;
|
||||
|
||||
if (infile_name == NULL)
|
||||
*in = stdin;
|
||||
else
|
||||
*in = fopen_safe(infile_name, "rb");
|
||||
}
|
||||
|
||||
if (*in == NULL)
|
||||
return;
|
||||
|
||||
void open_out_file(FILE ** out, char *outfile_name)
|
||||
{
|
||||
*out = NULL;
|
||||
if (global_options.use_stdout)
|
||||
*out = stdout;
|
||||
else if (outfile_name != NULL)
|
||||
@ -404,7 +402,9 @@ int compress_file(void)
|
||||
global_options.outfile_name;
|
||||
char *suffix = global_options.suffix;
|
||||
size_t infile_name_len = global_options.infile_name_len;
|
||||
size_t outfile_name_len = global_options.outfile_name_len;
|
||||
size_t suffix_len = global_options.suffix_len;
|
||||
|
||||
int level = global_options.level;
|
||||
|
||||
if (suffix == NULL) {
|
||||
@ -419,13 +419,24 @@ int compress_file(void)
|
||||
}
|
||||
|
||||
if (outfile_name == NULL && infile_name != NULL && !global_options.use_stdout) {
|
||||
outfile_name = malloc_safe(infile_name_len + suffix_len + 1);
|
||||
outfile_name_len = infile_name_len + suffix_len;
|
||||
outfile_name = malloc_safe(outfile_name_len + 1);
|
||||
strcpy(outfile_name, infile_name);
|
||||
strcat(outfile_name, suffix);
|
||||
}
|
||||
|
||||
open_files(&in, &out, infile_name, infile_name_len, outfile_name);
|
||||
if (in == NULL || out == NULL)
|
||||
open_in_file(&in, infile_name);
|
||||
if (in == NULL)
|
||||
goto compress_file_cleanup;
|
||||
|
||||
if (infile_name_len != 0 && infile_name_len == outfile_name_len
|
||||
&& strncmp(infile_name, outfile_name, infile_name_len) == 0) {
|
||||
log_print(ERROR, "igzip: Error input and output file names must differ\n");
|
||||
goto compress_file_cleanup;
|
||||
}
|
||||
|
||||
open_out_file(&out, outfile_name);
|
||||
if (out == NULL)
|
||||
goto compress_file_cleanup;
|
||||
|
||||
inbuf_size = BLOCK_SIZE;
|
||||
@ -557,8 +568,18 @@ int decompress_file(void)
|
||||
outfile_name[outfile_name_len] = 0;
|
||||
}
|
||||
|
||||
open_files(&in, &out, infile_name, infile_name_len, outfile_name);
|
||||
if (in == NULL || out == NULL)
|
||||
open_in_file(&in, infile_name);
|
||||
if (in == NULL)
|
||||
goto decompress_file_cleanup;
|
||||
|
||||
if (infile_name_len != 0 && infile_name_len == outfile_name_len
|
||||
&& strncmp(infile_name, outfile_name, infile_name_len) == 0) {
|
||||
log_print(ERROR, "igzip: Error input and output file names must differ\n");
|
||||
goto decompress_file_cleanup;
|
||||
}
|
||||
|
||||
open_out_file(&out, outfile_name);
|
||||
if (out == NULL)
|
||||
goto decompress_file_cleanup;
|
||||
|
||||
file_time = get_posix_filetime(in);
|
||||
|
@ -174,5 +174,20 @@ $IGZIP -dq $file1 &> /dev/null && ret=1
|
||||
pass_check $ret "Quiet will not overwrite"
|
||||
clear_dir
|
||||
|
||||
# Input file and output file cannot be the same
|
||||
ret=0
|
||||
cp $TEST_FILE $file1 && $IGZIP $file1 -o $file1 &> /dev/null && ret=1
|
||||
$DIFF $TEST_FILE $file1 &> /dev/null || ret=1
|
||||
pass_check $ret "No in place compression"
|
||||
clear_dir
|
||||
|
||||
# Input file and output file cannot be the same
|
||||
ret=0
|
||||
cp $TEST_FILE $file1 && $IGZIP $file1 -o $file1$ds &> /dev/null || ret=1
|
||||
$IGZIP -do $file1 $file1 &> /dev/null && ret=1
|
||||
$DIFF $TEST_FILE $file1 &> /dev/null || ret=1
|
||||
pass_check $ret "No in place decompression"
|
||||
clear_dir
|
||||
|
||||
echo "Passed all cli checks"
|
||||
cleanup 0
|
||||
|
Loading…
x
Reference in New Issue
Block a user