Skip to content

Commit

Permalink
Fix #337 - Fix 'y -1' segfault
Browse files Browse the repository at this point in the history
  • Loading branch information
radare committed Nov 10, 2013
1 parent 1370731 commit 0903ccc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
23 changes: 16 additions & 7 deletions libr/core/yank.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,25 @@

#include "r_core.h"

R_API void r_core_yank_set (RCore *core, const char *str) {
R_API int r_core_yank_set (RCore *core, const char *str) {
free (core->yank_buf);
if (str) {
if (str && *str) {
core->yank_buf = (ut8*)strdup (str);
core->yank_off = core->offset;
core->yank_len = strlen (str);
} else {
core->yank_buf = NULL;
core->yank_len = 0;
return R_TRUE;
}
core->yank_buf = NULL;
core->yank_len = 0;
return R_FALSE;
}

R_API int r_core_yank(struct r_core_t *core, ut64 addr, int len) {
ut64 oldbsz = 0LL;
ut64 curseek = core->offset;
free (core->yank_buf);
if (len<0)
return R_FALSE;
core->yank_buf = (ut8 *)malloc (len);
if (addr != core->offset)
r_core_seek (core, addr, 1);
Expand All @@ -38,8 +41,8 @@ R_API int r_core_yank(struct r_core_t *core, ut64 addr, int len) {
}

R_API int r_core_yank_paste(RCore *core, ut64 addr, int len) {
if (len == 0)
len = core->yank_len;
if (len<0) return R_FALSE;
if (len == 0) len = core->yank_len;
if (len > core->yank_len)
len = core->yank_len;
r_core_write_at (core, addr, core->yank_buf, len);
Expand All @@ -62,6 +65,8 @@ R_API int r_core_yank_to(RCore *core, const char *_arg) {
pos = r_num_math (core->num, str+1);
str[0]=' ';
}
if (len<1)
return R_FALSE;
if ((str == NULL) || (pos == -1) || (len == 0)) {
eprintf ("Usage: yt [len] [dst-addr]\n");
free (arg);
Expand All @@ -74,6 +79,10 @@ R_API int r_core_yank_to(RCore *core, const char *_arg) {
}
#endif
buf = (ut8*)malloc (len);
if (!buf) {
free (arg);
return R_FALSE;
}
r_core_read_at (core, src, buf, len);
r_core_write_at (core, pos, buf, len);
free (buf);
Expand Down
2 changes: 1 addition & 1 deletion libr/include/r_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ R_API int r_core_write_op(RCore *core, const char *arg, char op);

R_API int r_core_yank(RCore *core, ut64 addr, int len);
R_API int r_core_yank_paste(RCore *core, ut64 addr, int len);
R_API void r_core_yank_set (RCore *core, const char *str);
R_API int r_core_yank_set (RCore *core, const char *str);
R_API int r_core_yank_to(RCore *core, const char *arg);

R_API int r_core_loadlibs(RCore *core);
Expand Down

0 comments on commit 0903ccc

Please sign in to comment.