Fix rz-test coverity issues (#1593)

* CID 316425: Resource leak (RESOURCE_LEAK)

* CID 316759: Dereference before null check (REVERSE_INULL)

* CID 354049: Dereference after null check (FORWARD_NULL)

* CID 315924: Out-of-bounds access (OVERRUN)
This commit is contained in:
Giovanni 2021-09-04 14:30:41 +02:00 committed by GitHub
parent 6aef990eef
commit cacce543b7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 6 deletions

View file

@ -406,10 +406,12 @@ RZ_API RzPVector *rz_test_load_asm_test_file(RzStrConstPool *strpool, const char
int bytesz = rz_hex_str2bin(hex, bytes);
if (bytesz == 0) {
eprintf(LINEFMT "Error: Expected hex chars.\n", file, linenum);
free(bytes);
goto fail;
}
if (bytesz < 0) {
eprintf(LINEFMT "Error: Odd number of hex chars: %s\n", file, linenum, hex);
free(bytes);
goto fail;
}

View file

@ -35,9 +35,9 @@ static RzSubprocessOutput *subprocess_runner(const char *file, const char *args[
RzSubprocessOutput *out = rz_subprocess_drain(proc);
if (out) {
out->timeout = r == RZ_SUBPROCESS_TIMEDOUT;
out->out = remove_cr(out->out);
out->err = remove_cr(out->err);
}
out->out = remove_cr(out->out);
out->err = remove_cr(out->err);
rz_subprocess_free(proc);
return out;
}
@ -463,7 +463,9 @@ RZ_API RzTestResultInfo *rz_test_run_test(RzTestRunConfig *config, RzTest *test)
RzAsmTestOutput *out = rz_test_run_asm_test(config, asm_test);
success = rz_test_check_asm_test(out, asm_test);
ret->asm_out = out;
ret->timeout = out->as_timeout || out->disas_timeout;
if (out) {
ret->timeout = out->as_timeout || out->disas_timeout;
}
ret->run_failed = !out;
break;
}
@ -472,7 +474,9 @@ RZ_API RzTestResultInfo *rz_test_run_test(RzTestRunConfig *config, RzTest *test)
RzSubprocessOutput *out = rz_test_run_json_test(config, json_test, subprocess_runner, NULL);
success = rz_test_check_json_test(out, json_test);
ret->proc_out = out;
ret->timeout = out->timeout;
if (out) {
ret->timeout = out->timeout;
}
ret->run_failed = !out;
break;
}
@ -481,7 +485,9 @@ RZ_API RzTestResultInfo *rz_test_run_test(RzTestRunConfig *config, RzTest *test)
RzSubprocessOutput *out = rz_test_run_fuzz_test(config, fuzz_test, subprocess_runner, NULL);
success = rz_test_check_fuzz_test(out);
ret->proc_out = out;
ret->timeout = out->timeout;
if (out) {
ret->timeout = out->timeout;
}
ret->run_failed = !out;
}
}

View file

@ -121,7 +121,7 @@ static bool rz_test_test_run_unit(void) {
}
static bool rz_test_chdir_fromtest(const char *test_path) {
if (*test_path == '@') {
if (!test_path || *test_path == '@') {
test_path = "";
}
char *abs_test_path = rz_file_abspath(test_path);