forked from enlightenment/enlightenment
e: handle e_util_head_exec display env
Clean up the code to set DISPLAY env so it is safe and correct.
This commit is contained in:
parent
65a1ed752e
commit
5ca535383f
|
@ -148,34 +148,27 @@ e_util_head_exec(int head, const char *cmd)
|
|||
{
|
||||
char *penv_display;
|
||||
char *p1, *p2;
|
||||
char buf[4096], buf2[32];
|
||||
char buf[4096];
|
||||
int ok = 0;
|
||||
Ecore_Exe *exe;
|
||||
|
||||
penv_display = getenv("DISPLAY");
|
||||
if (!penv_display) return 0;
|
||||
penv_display = strdup(penv_display);
|
||||
if (!penv_display) return 0;
|
||||
/* set env vars */
|
||||
p1 = strrchr(penv_display, ':');
|
||||
p2 = strrchr(penv_display, '.');
|
||||
if ((p1) && (p2) && (p2 > p1)) /* "blah:x.y" */
|
||||
{
|
||||
/* yes it could overflow... but who will overflow DISPLAY eh? why? to
|
||||
* "exploit" your own applications running as you?
|
||||
*/
|
||||
strncpy(buf, penv_display, sizeof(buf));
|
||||
buf[p2 - penv_display + 1] = 0;
|
||||
snprintf(buf2, sizeof(buf2), "%i", head);
|
||||
strcat(buf, buf2);
|
||||
*p2 = 0;
|
||||
snprintf(buf, sizeof(buf), "%s.%i", penv_display, head);
|
||||
*p2 = '.';
|
||||
}
|
||||
else if (p1) /* "blah:x */
|
||||
{
|
||||
strncpy(buf, penv_display, sizeof(buf));
|
||||
snprintf(buf2, sizeof(buf2), ".%i", head);
|
||||
strcat(buf, buf2);
|
||||
}
|
||||
snprintf(buf, sizeof(buf), "%s.%i", penv_display, head);
|
||||
else
|
||||
strncpy(buf, penv_display, sizeof(buf));
|
||||
eina_strlcpy(buf, penv_display, sizeof(buf));
|
||||
|
||||
ok = 1;
|
||||
exe = ecore_exe_run(cmd, NULL);
|
||||
|
@ -190,11 +183,8 @@ e_util_head_exec(int head, const char *cmd)
|
|||
}
|
||||
|
||||
/* reset env vars */
|
||||
if (penv_display)
|
||||
{
|
||||
e_util_env_set("DISPLAY", penv_display);
|
||||
free(penv_display);
|
||||
}
|
||||
e_util_env_set("DISPLAY", penv_display);
|
||||
free(penv_display);
|
||||
return ok;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue