Skip to content

Commit

Permalink
/e: Fix matching at block end (#4870)
Browse files Browse the repository at this point in the history
  • Loading branch information
kazarmy authored Jan 30, 2025
1 parent d61b1c9 commit 2c1a07d
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
20 changes: 17 additions & 3 deletions librz/core/cmd/cmd_search.c
Original file line number Diff line number Diff line change
Expand Up @@ -1236,7 +1236,7 @@ static void do_asm_search(RzCore *core, struct search_parameters *param, const c

static void do_string_search(RzCore *core, RzInterval search_itv, struct search_parameters *param) {
ut64 at;
ut8 *buf;
ut8 *buf = NULL;
RzSearch *search = core->search;

if (param->outmode == RZ_MODE_JSON) {
Expand All @@ -1259,7 +1259,7 @@ static void do_string_search(RzCore *core, RzInterval search_itv, struct search_
/* TODO: launch search in background support */
// REMOVE OLD FLAGS rz_core_cmdf (core, "f-%s*", rz_config_get (core->config, "search.prefix"));
rz_search_set_callback(core->search, &_cb_hit, param);
if (!(buf = malloc(core->blocksize))) {
if (!param->regex_search && !(buf = malloc(core->blocksize))) {
return;
}
if (search->bckwrds) {
Expand Down Expand Up @@ -1312,7 +1312,21 @@ static void do_string_search(RzCore *core, RzInterval search_itv, struct search_
}
(void)rz_io_read_at(core->io, at - len, buf, len);
} else {
len = RZ_MIN(core->blocksize, to - at);
if (param->regex_search) {
// Since regex match length can be infinite, for 100% correctness
// it is not possible to chunk the search. This could be a problem
// for large binaries.
free(buf);
len = to - at;
if (!(buf = malloc(len))) {
RZ_LOG_ERROR("Cannot allocate search buffer"
" of size 0x%" PFMT64x "\n",
len);
return;
}
} else {
len = RZ_MIN(core->blocksize, to - at);
}
if (!rz_io_is_valid_offset(core->io, at, 0)) {
break;
}
Expand Down
25 changes: 25 additions & 0 deletions test/db/cmd/regexp
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,28 @@ Searching in [0x0-0x200]
hits: 1
EOF
RUN

NAME=/e at block end
FILE==
CMDS=<<EOF
b 0x100
w bcccde @ 0xfe
w bd @ 0x1fe
e scr.color=1
/e /b.*d/
echo ----
/e /b.*d$/
EOF
EXPECT=<<EOF
0x000000fe hit0_0 .bcccde.
0x000001fe hit0_1 .bd.
----
0x000001fe hit1_0 .bd.
EOF
EXPECT_ERR=<<EOF
Searching in [0x0-0x200]
hits: 2
Searching in [0x0-0x200]
hits: 1
EOF
RUN
Expand Down

0 comments on commit 2c1a07d

Please sign in to comment.