Fix truncated issue with long dir.prefix is used

- Small optimization when concatenating the home
This commit is contained in:
pancake 2019-02-11 15:47:20 +01:00
parent 1936f2d047
commit a488760903
3 changed files with 8 additions and 8 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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);