Escape environment vars in the default rarun profile (#17441) ##debug

This commit is contained in:
Zi Fan 2020-09-07 17:16:57 +08:00 committed by GitHub
parent e7b86490e1
commit ea1151d143
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 10 deletions

View File

@ -256,6 +256,7 @@ R_API int r_run_config_env(RRunProfile *p);
R_API int r_run_start(RRunProfile *p);
R_API void r_run_reset(RRunProfile *p);
R_API bool r_run_parsefile(RRunProfile *p, const char *b);
R_API char *r_run_get_environ_profile(char **environ);
/* rapipe */
R_API R2Pipe *rap_open(const char *cmd);

View File

@ -386,16 +386,8 @@ R_API int r_main_radare2(int argc, const char **argv) {
r_sys_env_init ();
// Create rarun2 profile with startup environ
char *envprofile = NULL;
char **e = r_sys_get_environ ();
if (e) {
RStrBuf *sb = r_strbuf_new (NULL);
while (e && *e) {
r_strbuf_appendf (sb, "setenv=%s\n", *e);
e++;
}
envprofile = r_strbuf_drain (sb);
}
char **env = r_sys_get_environ ();
char *envprofile = r_run_get_environ_profile (env);
if (r_sys_getenv_asbool ("R2_DEBUG")) {
char *sysdbg = r_sys_getenv ("R2_DEBUG_TOOL");

View File

@ -1228,3 +1228,25 @@ R_API int r_run_start(RRunProfile *p) {
}
return 0;
}
R_API char *r_run_get_environ_profile(char **env) {
if (!env) {
return NULL;
}
RStrBuf *sb = r_strbuf_new (NULL);
while (*env) {
char *k = strdup (*env);
char *v = strchr (k, '=');
if (v) {
*v++ = 0;
v = r_str_escape_latin1 (v, false, true, true);
if (v) {
r_strbuf_appendf (sb, "setenv=%s=\"%s\"\n", k, v);
free (v);
}
}
free (k);
env++;
}
return r_strbuf_drain (sb);
}