summaryrefslogtreecommitdiff
path: root/src/lib/eina
diff options
context:
space:
mode:
authorMarcel Hollerbach <mail@marcel-hollerbach.de>2019-04-27 11:57:50 +0200
committerMarcel Hollerbach <mail@marcel-hollerbach.de>2019-04-27 12:31:39 +0200
commit60af61809858df8b0bbb2042a9ebb9b911331827 (patch)
treeb80a1949a6082e906a0a7690a02e36598d99cad8 /src/lib/eina
parent78563a395e1d9140eb6a67e7e7f9aff34af10e4b (diff)
eina_vpath do not pass things through snprintf when not expected.
lets assume a user passes in a string like "blabla%dehydra" then %d will be resolved by snprintf. Which is probebly not what we want. This resolves this case and ensures that eina_vpath_resolve does not get piped through snprintf Reviewed-by: Dave Andreoli <dave@gurumeditation.it> Differential Revision: https://phab.enlightenment.org/D8753
Diffstat (limited to 'src/lib/eina')
-rw-r--r--src/lib/eina/eina_vpath.c177
1 files changed, 94 insertions, 83 deletions
diff --git a/src/lib/eina/eina_vpath.c b/src/lib/eina/eina_vpath.c
index 25fa901..aa7b46b 100644
--- a/src/lib/eina/eina_vpath.c
+++ b/src/lib/eina/eina_vpath.c
@@ -218,37 +218,9 @@ _fetch_user_homedir(char **str, const char *name, const char *error)
218#endif 218#endif
219} 219}
220 220
221 221static int
222EAPI char * 222_eina_vpath_resolve(const char *path, char *str, size_t size)
223eina_vpath_resolve(const char* path)
224{
225 char buf[PATH_MAX];
226
227 if (eina_vpath_resolve_snprintf(buf, sizeof(buf), path) > 0)
228 return strdup(buf);
229 return NULL;
230}
231
232EAPI int
233eina_vpath_resolve_snprintf(char *str, size_t size, const char *format, ...)
234{ 223{
235 va_list args;
236 char *path;
237 // XXX: implement parse of path then look up in hash if not just create
238 // object where path and result are the same and return that with
239 // path set and result set to resolved path - return obj handler calls
240 // "do" on object to get the result inside fetched or failed callback.
241 // if it's a url then we need a new classs that overrides the do and
242 // begins a fetch and on finish calls the event cb or when wait is called
243 /* FIXME: not working for WIndows */
244 // /* <- full path
245
246 path = alloca(size + 1);
247
248 va_start(args, format);
249 vsnprintf(path, size, format, args);
250 va_end(args);
251
252 if (path[0] == '~') 224 if (path[0] == '~')
253 { 225 {
254 char *home = NULL; 226 char *home = NULL;
@@ -261,7 +233,8 @@ eina_vpath_resolve_snprintf(char *str, size_t size, const char *format, ...)
261 // ~username/ <- homedir of user "username" 233 // ~username/ <- homedir of user "username"
262 else 234 else
263 { 235 {
264 char *p, *name; 236 const char *p;
237 char *name;
265 238
266 for (p = path + 1; *p; p++) 239 for (p = path + 1; *p; p++)
267 { 240 {
@@ -279,60 +252,98 @@ eina_vpath_resolve_snprintf(char *str, size_t size, const char *format, ...)
279 { 252 {
280 return snprintf(str, size, "%s%s", home, path); 253 return snprintf(str, size, "%s%s", home, path);
281 } 254 }
282 } 255 }
283 // (:xxx:)/* ... <- meta hash table 256 // (:xxx:)/* ... <- meta hash table
284 else if ((path[0] == '(') && (path[1] == ':')) 257 else if ((path[0] == '(') && (path[1] == ':'))
285 { 258 {
286 const char *p, *end, *meta; 259 const char *p, *end, *meta;
287 char *name; 260 char *name;
288 int max_len = strlen(path); 261 int max_len = strlen(path);
289 Eina_Bool found = EINA_FALSE; 262 Eina_Bool found = EINA_FALSE;
290 263
291 for (p = path + 2; p <= path + max_len - 2; p++) 264 for (p = path + 2; p <= path + max_len - 2; p++)
292 { 265 {
293 if ((p[0] ==':') && (p[1] == ')')) 266 if ((p[0] ==':') && (p[1] == ')'))
294 { 267 {
295 end = p; 268 end = p;
296 found = EINA_TRUE; 269 found = EINA_TRUE;
297 break; 270 break;
298 } 271 }
299 } 272 }
300 p += 2; 273 p += 2;
301 274
302 if (!found) 275 if (!found)
303 { 276 {
304 ERR("(: Needs to have a matching ':)'\nThe string was: %s", path); 277 ERR("(: Needs to have a matching ':)'\nThe string was: %s", path);
305 return 0; 278 return 0;
306 } 279 }
307 280
308 if (*p != '/') 281 if (*p != '/')
309 { 282 {
310 ERR("A / is expected after :)\nThe string was: %s", path); 283 ERR("A / is expected after :)\nThe string was: %s", path);
311 return 0; 284 return 0;
312 } 285 }
313 286
314 if (found) 287 if (found)
315 { 288 {
316 name = alloca(end - path); 289 name = alloca(end - path);
317 strncpy(name, path + 2, end - path - 2); 290 strncpy(name, path + 2, end - path - 2);
318 name[end - path - 2] = 0; 291 name[end - path - 2] = 0;
319 meta = _eina_vpath_data_get(name); 292 meta = _eina_vpath_data_get(name);
320 if (meta) 293 if (meta)
321 { 294 {
322 return snprintf(str, size, "%s%s", meta, end + 2); 295 return snprintf(str, size, "%s%s", meta, end + 2);
323 } 296 }
324 else 297 else
325 { 298 {
326 ERR("Meta key '%s' was not registered!\nThe string was: %s", name, path); 299 ERR("Meta key '%s' was not registered!\nThe string was: %s", name, path);
327 return 0; 300 return 0;
328 } 301 }
329 } 302 }
330 } 303 }
331 //just return the path, since we assume that this is a normal path 304 //just return the path, since we assume that this is a normal path
332 else 305 else
333 { 306 {
334 return snprintf(str, size, "%s", path); 307 return snprintf(str, size, "%s", path);
335 } 308 }
309 str[0] = '\0';
310 return 0;
311}
312
313EAPI char *
314eina_vpath_resolve(const char* path)
315{
316 char buf[PATH_MAX];
317
318 if (_eina_vpath_resolve(path, buf, sizeof(buf)) > 0)
319 return strdup(buf);
320 return NULL;
321}
322
323EAPI int
324eina_vpath_resolve_snprintf(char *str, size_t size, const char *format, ...)
325{
326 va_list args;
327 char *path;
328 int r;
329
330 // XXX: implement parse of path then look up in hash if not just create
331 // object where path and result are the same and return that with
332 // path set and result set to resolved path - return obj handler calls
333 // "do" on object to get the result inside fetched or failed callback.
334 // if it's a url then we need a new classs that overrides the do and
335 // begins a fetch and on finish calls the event cb or when wait is called
336 /* FIXME: not working for WIndows */
337 // /* <- full path
338
339 path = alloca(size + 1);
340
341 va_start(args, format);
342 vsnprintf(path, size, format, args);
343 va_end(args);
344
345 r = _eina_vpath_resolve(path, str, size);
346 if (r > 0) return r;
336 347
337 ERR("The path has to start with either '~/' or '(:NAME:)/' or be a normal path \nThe string was: %s", path); 348 ERR("The path has to start with either '~/' or '(:NAME:)/' or be a normal path \nThe string was: %s", path);
338 349