Fix incorrect ragg2 empty string check (#17202)

* Check for empty path string only if |file| actually exists
* Add a test that would have spot this bug in first place
This commit is contained in:
phakeobj 2020-07-03 22:09:42 +03:00 committed by GitHub
parent b027858c95
commit 3f0cfff3d5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 9 deletions

View File

@ -343,13 +343,6 @@ R_API int r_main_ragg2(int argc, const char **argv) {
file = argv[opt.ind];
}
if (R_STR_ISEMPTY (opt.arg)) {
eprintf ("Cannot open empty path\n");
free (sequence);
r_egg_free (egg);
return 1;
}
if (bits == 64) {
if (!strcmp (format, "mach0")) {
format = "mach064";
@ -378,6 +371,10 @@ R_API int r_main_ragg2(int argc, const char **argv) {
// initialize egg
r_egg_setup (egg, arch, bits, 0, os);
if (file) {
if (R_STR_ISEMPTY (file)) {
eprintf ("Cannot open empty path\n");
goto fail;
}
if (!strcmp (file, "-")) {
char buf[1024];
for (;;) {

View File

@ -147,7 +147,7 @@ EOF
RUN
NAME=ragg2 empty include
FILE=-
FILE=bins/other/ragg2/hi.c
CMDS=!ragg2 -I "" bins/other/ragg2/hi.c
EXPECT_ERR=<<EOF
Cannot open empty include path
@ -155,9 +155,25 @@ EOF
RUN
NAME=ragg2 empty contents
FILE=-
FILE=bins/other/ragg2/hi.c
CMDS=!ragg2 -C "" bins/other/ragg2/hi.c
EXPECT_ERR=<<EOF
Cannot open empty contents path
EOF
RUN
NAME=ragg2 debruijn sequence 1
FILE=-
CMDS=!ragg2 -r -P 2; ?e
EXPECT=<<EOF
AA
EOF
RUN
NAME=ragg2 debruijn sequence 2
FILE=-
CMDS=!ragg2 -P 2 -r; ?e
EXPECT=<<EOF
AA
EOF
RUN