Fix null deref crash in RTable and improve C, ##shell

This commit is contained in:
pancake 2022-08-20 02:17:09 +02:00
parent 0fb54f9413
commit 9fea483cf4
3 changed files with 20 additions and 18 deletions

View File

@ -538,17 +538,19 @@ static void print_meta_list(RAnal *a, int type, int rad, ut64 addr, const char *
}
beach:
if (t) {
if (tq) {
r_table_query (t, tq);
if (tq) {
r_table_query (t, tq);
}
if (!strstr (tq, "?")) {
if (t) {
char *s = r_table_tostring (t);
r_cons_printf ("%s\n", s);
free (s);
} else if (pj) {
pj_end (pj);
r_cons_printf ("%s\n", pj_string (pj));
pj_free (pj);
}
char *s = r_table_tostring (t);
r_cons_printf ("%s\n", s);
free (s);
} else if (pj) {
pj_end (pj);
r_cons_printf ("%s\n", pj_string (pj));
pj_free (pj);
}
}

View File

@ -1146,7 +1146,7 @@ static int cmd_meta(void *data, const char *input) {
if (!input[0] || input[1] == '.') {
r_meta_print_list_at (core->anal, core->offset, *input, input + 2);
} else {
r_meta_print_list_all (core->anal, R_META_TYPE_ANY, *input, input + 2);
r_meta_print_list_all (core->anal, R_META_TYPE_ANY, *input, input + 1);
}
break;
}

View File

@ -4,8 +4,8 @@
#include "r_cons.h"
// cant do that without globals because RList doesnt have void *user :(
static int Gnth = 0;
static RListComparator Gcmp = NULL;
static R_TH_LOCAL int Gnth = 0;
static R_TH_LOCAL RListComparator Gcmp = NULL;
static int sortString(const void *a, const void *b) {
return strcmp (a, b);
@ -706,23 +706,23 @@ R_API void r_table_filter(RTable *t, int nth, int op, const char *un) {
break;
case '=':
if (nv == 0) {
match = !strcmp (nn, un);
match = (nn && un && !strcmp (nn, un));
} else {
match = (nv == uv);
}
break;
case '!':
if (nv == 0) {
match = strcmp (nn, un);
match = (!nn || !un || strcmp (nn, un));
} else {
match = (nv != uv);
}
break;
case '$':
match = strstr (nn, un) == NULL;
match = !nn || !un || strstr (nn, un) == NULL;
break;
case '~':
match = strstr (nn, un);
match = nn&&un&&strstr (nn, un);
break;
case 's':
match = strlen (nn) == atoi (un);
@ -1172,7 +1172,7 @@ R_API bool r_table_query(RTable *t, const char *q) {
} else {
int op = __resolveOperation (operation);
if (op == -1) {
eprintf ("Invalid operation (%s)\n", operation);
R_LOG_ERROR ("Invalid table operation (%s)", operation);
} else {
r_table_filter (t, col, op, operand);
}