From aeb6fcbbbe818428207629455efb0580f5167123 Mon Sep 17 00:00:00 2001 From: raster Date: Thu, 25 Aug 2011 10:01:22 +0000 Subject: [PATCH] =?utf8?q?From:=20J=C3=A9r=C3=A9my=20Zurcher=20=20Subject:=20[E-devel]=20patch=20:=20eina=5Fprefix=20+=20?= =?utf8?q?elementary=5Ftest?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit please find attached a small patch for eina_prefix it prevent segfault when for instance no elm_app_compile_*_dir_set is called prior to elm_app_info_set and another one for elementary/src/bin/test*.c which tends to replace usage of PACKAGE_DATA_DIR with elm_app_data_dir_get git-svn-id: svn+ssh://svn.enlightenment.org/var/svn/e/trunk/eina@62795 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33 --- ChangeLog | 5 +++++ src/lib/eina_prefix.c | 60 +++++++++++++++++++++++++++++++-------------------- 2 files changed, 42 insertions(+), 23 deletions(-) diff --git a/ChangeLog b/ChangeLog index 53e1b39..8e9cf08 100644 --- a/ChangeLog +++ b/ChangeLog @@ -126,3 +126,8 @@ 2011-08-03 Myungjae Lee * Fix eina_share_common_del and eina_share_common_ref to release lock on failure. + +2011-08-25 Jérémy Zurcher + + * Max eina_prefix more robust so it handles null bin and share + dirs better etc. diff --git a/src/lib/eina_prefix.c b/src/lib/eina_prefix.c index 84ba5bb..01163dc 100644 --- a/src/lib/eina_prefix.c +++ b/src/lib/eina_prefix.c @@ -103,7 +103,7 @@ struct _Eina_Prefix unsigned char env_used : 1; }; -#define STRDUP_REP(x, y) do { if (x) free(x); x = strdup(y); } while (0) +#define STRDUP_REP(x, y) do { if (x) free(x); x = NULL; if (y) { x = strdup(y); } } while (0) #define IF_FREE_NULL(p) do { if (p) { free(p); p = NULL; } } while (0) #define DBG(fmt, args...) do { if (getenv("EINA_PREFIX_DEBUG")) fprintf(stderr, fmt, ##args); } while (0) @@ -204,8 +204,11 @@ _try_argv(Eina_Prefix *pfx, const char *argv0) { char *path, *p, *cp, *s; int len, lenexe; - char buf[PATH_MAX], buf2[PATH_MAX], buf3[PATH_MAX]; + char *buf, *buf2, *buf3; + buf = alloca(PATH_MAX); + buf2 = alloca(PATH_MAX); + buf3 = alloca(PATH_MAX); DBG("Try argv0 = %s\n", argv0); /* 1. is argv0 abs path? */ #ifdef _WIN32 @@ -286,9 +289,10 @@ _try_argv(Eina_Prefix *pfx, const char *argv0) static int _get_env_var(char **var, const char *env, const char *prefix, const char *dir) { - char buf[PATH_MAX]; + char *buf; const char *s = getenv(env); + buf = alloca(PATH_MAX); DBG("Try env var %s\n", env); if (s) { @@ -353,7 +357,7 @@ eina_prefix_new(const char *argv0, void *symbol, const char *envprefix, const char *pkg_data, const char *pkg_locale) { Eina_Prefix *pfx; - char *p, buf[4096], *tmp, *magic = NULL; + char *p, *buf, *tmp, *magic = NULL; struct stat st; const char *p1, *p2; const char *pkg_bin_p = NULL; @@ -365,6 +369,7 @@ eina_prefix_new(const char *argv0, void *symbol, const char *envprefix, const char *datadir = "share"; const char *localedir = "share"; + buf = alloca(PATH_MAX); DBG("EINA PREFIX: argv0=%s, symbol=%p, magicsharefile=%s, envprefix=%s\n", argv0, symbol, magicsharefile, envprefix); pfx = calloc(1, sizeof(Eina_Prefix)); if (!pfx) return NULL; @@ -428,32 +433,41 @@ eina_prefix_new(const char *argv0, void *symbol, const char *envprefix, * all with a common prefix that can be relocated */ /* 1. check last common char in bin and lib strings */ - for (p1 = pkg_bin, p2 = pkg_lib; *p1 && *p2; p1++, p2++) + if ( pkg_bin && pkg_lib ) { - if (*p1 != *p2) - { - pkg_bin_p = p1; - pkg_lib_p = p2; - break; - } + for (p1 = pkg_bin, p2 = pkg_lib; *p1 && *p2; p1++, p2++) + { + if (*p1 != *p2) + { + pkg_bin_p = p1; + pkg_lib_p = p2; + break; + } + } } /* 1. check last common char in bin and data strings */ - for (p1 = pkg_bin, p2 = pkg_data; *p1 && *p2; p1++, p2++) + if (pkg_bin && pkg_data) { - if (*p1 != *p2) - { - pkg_data_p = p2; - break; - } + for (p1 = pkg_bin, p2 = pkg_data; *p1 && *p2; p1++, p2++) + { + if (*p1 != *p2) + { + pkg_data_p = p2; + break; + } + } } /* 1. check last common char in bin and locale strings */ - for (p1 = pkg_bin, p2 = pkg_locale; *p1 && *p2; p1++, p2++) + if (pkg_bin && pkg_locale) { - if (*p1 != *p2) - { - pkg_locale_p = p2; - break; - } + for (p1 = pkg_bin, p2 = pkg_locale; *p1 && *p2; p1++, p2++) + { + if (*p1 != *p2) + { + pkg_locale_p = p2; + break; + } + } } /* 2. if all the common string offsets match we compiled with a common prefix */ if (((pkg_bin_p - pkg_bin) == (pkg_lib_p - pkg_lib)) -- 2.7.4