Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #16347: o+ sets maps as writable like oo+ #16381

Merged
merged 3 commits into from
Apr 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions libr/core/cmd_open.c
Original file line number Diff line number Diff line change
Expand Up @@ -1390,6 +1390,7 @@ static int cmd_open(void *data, const char *input) {
break;
case '+': // "o+"
perms |= R_PERM_W;
/* fallthrough */
case ' ': // "o" "o "
ptr = input + 1;
argv = r_str_argv (ptr, &argc);
Expand Down Expand Up @@ -1422,6 +1423,20 @@ static int cmd_open(void *data, const char *input) {
addr = UT64_MAX;
}
r_core_bin_load (core, argv0, addr);
if (*input == '+') { // "o+"
RIODesc *desc = r_io_desc_get (core->io, fd);
if (desc && (desc->perm & R_PERM_W)) {
SdbListIter *iter;
RIOMap *map;
ls_foreach_prev (core->io->maps, iter, map) {
if (map->fd == fd) {
map->perm |= R_PERM_WX;
}
}
} else {
eprintf ("Error: %s is not writable\n", argv0);
}
}
} else {
eprintf ("cannot open file %s\n", argv0);
}
Expand Down
23 changes: 23 additions & 0 deletions test/new/db/cmd/cmd_open
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,29 @@ EXPECT=<<EOF
EOF
RUN

NAME=o+ writable maps fix
FILE=--
CMDS=<<EOF
o+ ../bins/elf/ls
om
# Possible parallelism problem
# ?e
# pv1
# $old=`pv1`
# wx 0x90
# pv1
# wx `$old?`
# pv1
EOF
EXPECT=<<EOF
5 fd: 3 +0x00000000 0x00000000 - 0x0000347f rwx fmap.LOAD0
4 fd: 3 +0x00004000 0x00004000 - 0x00016790 rwx fmap.LOAD1
3 fd: 3 +0x00017000 0x00017000 - 0x0001f7bf rwx fmap.LOAD2
2 fd: 3 +0x00020050 0x00021050 - 0x00022267 rwx fmap.LOAD3
1 fd: 4 +0x00000000 0x00022268 - 0x00023557 rw- mmap.LOAD3
EOF
RUN

NAME=o-*
FILE=-
EXPECT=<<EOF
Expand Down