Fix s390x rax2 -I & memleak (#18151)

This commit is contained in:
Liumeo 2021-01-01 16:48:28 -05:00 committed by GitHub
parent b69355bb84
commit a637aa281d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 7 deletions

View File

@ -576,16 +576,14 @@ dotherax:
return true;
} else if (flags & (1 << 23)) { // -I
if (strchr (str, '.')) {
ut32 ip32 = 0;
ut8 *ip = (ut8*)&ip32;
sscanf (str, "%hhd.%hhd.%hhd.%hhd", &ip[0], &ip[1], &ip[2], &ip[3]);
ut8 ip[4];
sscanf (str, "%hhd.%hhd.%hhd.%hhd", ip, ip + 1, ip + 2, ip + 3);
ut32 ip32 = ip[0] | (ip[1] << 8) | (ip[2] << 16) | (ip[3] << 24);
printf ("0x%08x\n", ip32);
} else {
ut32 ip32 = (ut32)r_num_math (NULL, str);
ut8 *ip = (ut8*)&ip32;
char ipaddr[32];
snprintf (ipaddr, sizeof (ipaddr), "%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]);
printf ("%s\n", ipaddr);
ut8 ip[4] = { ip32 & 0xff, (ip32 >> 8) & 0xff, (ip32 >> 16) & 0xff, ip32 >> 24 };
printf ("%d.%d.%d.%d\n", ip[0], ip[1], ip[2], ip[3]);
}
return true;
}
@ -643,6 +641,7 @@ R_API int r_main_rax2(int argc, const char **argv) {
char *argv_i = strdup (argv[i]);
r_str_unescape (argv_i);
rax (num, argv_i, 0, i == argc - 1, &flags, &fm);
free (argv_i);
}
}
r_num_free (num);

View File

@ -758,6 +758,7 @@ R_API int r_sys_cmd_str_full(const char *cmd, const char *input, char **output,
} else {
free (outputptr);
}
free (mysterr);
return ret;
}
return false;

View File

@ -6,6 +6,14 @@ EXPECT=<<EOF
EOF
RUN
NAME=rax2 -I 185.172.110.210
FILE=-
CMDS=!rax2 -I 185.172.110.210
EXPECT=<<EOF
0xd26eacb9
EOF
RUN
NAME=rax2 =10 0x46
FILE=-
CMDS=!rax2 =10 0x46