From a488760903f11ebeaee5b2c94769225604a36435 Mon Sep 17 00:00:00 2001 From: pancake Date: Mon, 11 Feb 2019 15:47:20 +0100 Subject: [PATCH] Fix truncated issue with long dir.prefix is used - Small optimization when concatenating the home --- libr/core/core.c | 4 ++-- libr/util/str.c | 7 ++++--- libr/util/sys.c | 5 ++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/libr/core/core.c b/libr/core/core.c index 26476863fc..9c98ff2c23 100644 --- a/libr/core/core.c +++ b/libr/core/core.c @@ -2035,8 +2035,8 @@ R_API const char *r_core_anal_optype_colorfor(RCore *core, ut64 addr, bool verbo static void r_core_setenv (RCore *core) { char *e = r_sys_getenv ("PATH"); - char *h = r_str_home (R2_HOME_BIN R_SYS_ENVSEP); - char *n = r_str_newf ("%s%s", h, e); + char *h = r_str_home (R2_HOME_BIN); + char *n = r_str_newf ("%s%s%s", h, R_SYS_ENVSEP, e); r_sys_setenv ("PATH", n); free (n); free (h); diff --git a/libr/util/str.c b/libr/util/str.c index 06f9a5119d..3d130607ea 100644 --- a/libr/util/str.c +++ b/libr/util/str.c @@ -304,10 +304,11 @@ R_API char *r_str_home(const char *str) { if (!dst) { goto fail; } - strcpy (dst, home); + int home_len = strlen (home); + memcpy (dst, home, home_len + 1); if (str) { - strcat (dst, R_SYS_DIR); - strcat (dst, str); + dst[home_len] = R_SYS_DIR[0]; + strcpy (dst + home_len + 1, str); } fail: free (home); diff --git a/libr/util/sys.c b/libr/util/sys.c index f35a908f3c..17fba2e884 100644 --- a/libr/util/sys.c +++ b/libr/util/sys.c @@ -1057,14 +1057,13 @@ R_API bool r_sys_tts(const char *txt, bool bg) { return false; } -static char prefix[128] = {0}; - R_API const char *r_sys_prefix(const char *pfx) { + static char prefix[1024] = {0}; if (!*prefix) { r_str_ncpy (prefix, R2_PREFIX, sizeof (prefix)); } if (pfx) { - if (strlen (pfx) >= sizeof (prefix) -1) { + if (strlen (pfx) >= sizeof (prefix) - 1) { return NULL; } r_str_ncpy (prefix, pfx, sizeof (prefix) - 1);