summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Dransfeld <sd@tango.flipp.net>2013-12-08 22:30:04 +0100
committerSebastian Dransfeld <sd@tango.flipp.net>2013-12-08 22:46:12 +0100
commit5ca535383fc9a5396c6893c4e03277696e39648e (patch)
tree8a0f68b7ebfbd8bdcf4a35bf34d49e5ce7702534
parent65a1ed752ed08de58d2eea550ad1bbc2d451e8d9 (diff)
e: handle e_util_head_exec display env
Clean up the code to set DISPLAY env so it is safe and correct.
-rw-r--r--src/bin/e_utils.c28
1 files changed, 9 insertions, 19 deletions
diff --git a/src/bin/e_utils.c b/src/bin/e_utils.c
index abbf72695..93f4daae7 100644
--- a/src/bin/e_utils.c
+++ b/src/bin/e_utils.c
@@ -148,34 +148,27 @@ e_util_head_exec(int head, const char *cmd)
148{ 148{
149 char *penv_display; 149 char *penv_display;
150 char *p1, *p2; 150 char *p1, *p2;
151 char buf[4096], buf2[32]; 151 char buf[4096];
152 int ok = 0; 152 int ok = 0;
153 Ecore_Exe *exe; 153 Ecore_Exe *exe;
154 154
155 penv_display = getenv("DISPLAY"); 155 penv_display = getenv("DISPLAY");
156 if (!penv_display) return 0; 156 if (!penv_display) return 0;
157 penv_display = strdup(penv_display); 157 penv_display = strdup(penv_display);
158 if (!penv_display) return 0;
158 /* set env vars */ 159 /* set env vars */
159 p1 = strrchr(penv_display, ':'); 160 p1 = strrchr(penv_display, ':');
160 p2 = strrchr(penv_display, '.'); 161 p2 = strrchr(penv_display, '.');
161 if ((p1) && (p2) && (p2 > p1)) /* "blah:x.y" */ 162 if ((p1) && (p2) && (p2 > p1)) /* "blah:x.y" */
162 { 163 {
163 /* yes it could overflow... but who will overflow DISPLAY eh? why? to 164 *p2 = 0;
164 * "exploit" your own applications running as you? 165 snprintf(buf, sizeof(buf), "%s.%i", penv_display, head);
165 */ 166 *p2 = '.';
166 strncpy(buf, penv_display, sizeof(buf));
167 buf[p2 - penv_display + 1] = 0;
168 snprintf(buf2, sizeof(buf2), "%i", head);
169 strcat(buf, buf2);
170 } 167 }
171 else if (p1) /* "blah:x */ 168 else if (p1) /* "blah:x */
172 { 169 snprintf(buf, sizeof(buf), "%s.%i", penv_display, head);
173 strncpy(buf, penv_display, sizeof(buf));
174 snprintf(buf2, sizeof(buf2), ".%i", head);
175 strcat(buf, buf2);
176 }
177 else 170 else
178 strncpy(buf, penv_display, sizeof(buf)); 171 eina_strlcpy(buf, penv_display, sizeof(buf));
179 172
180 ok = 1; 173 ok = 1;
181 exe = ecore_exe_run(cmd, NULL); 174 exe = ecore_exe_run(cmd, NULL);
@@ -190,11 +183,8 @@ e_util_head_exec(int head, const char *cmd)
190 } 183 }
191 184
192 /* reset env vars */ 185 /* reset env vars */
193 if (penv_display) 186 e_util_env_set("DISPLAY", penv_display);
194 { 187 free(penv_display);
195 e_util_env_set("DISPLAY", penv_display);
196 free(penv_display);
197 }
198 return ok; 188 return ok;
199} 189}
200 190