From 22f3a8ce4be4eb87d1a43f96c2f996e2fee38b84 Mon Sep 17 00:00:00 2001 From: darealshinji Date: Thu, 21 Dec 2017 16:40:15 +0100 Subject: [PATCH] get the right AppRun.c file, explicitly set \0 in sprintf --- AppRun.c.patch | 54 +++++++++++++++++++------------------------------- Makefile | 2 +- checkrt.c | 40 +++++++++++++++++++++++-------------- checkrt.h | 2 +- 4 files changed, 47 insertions(+), 51 deletions(-) diff --git a/AppRun.c.patch b/AppRun.c.patch index edf2497..6bacbd7 100644 --- a/AppRun.c.patch +++ b/AppRun.c.patch @@ -1,44 +1,30 @@ --- a/AppRun.c +++ b/AppRun.c -@@ -38,7 +38,7 @@ - exit( 1 ); \ - } while (0); - --#define NEW_LD_LIBRARY_PATH "LD_LIBRARY_PATH=./lib/:./lib/i386-linux-gnu/:./lib/x86_64-linux-gnu/:./lib32/:./lib64/:../lib/:../lib/i386-linux-gnu/:../lib/x86_64-linux-gnu/:../lib32/:../lib64/:%s" -+#define NEW_LD_LIBRARY_PATH "LD_LIBRARY_PATH=%s./lib/:./lib/i386-linux-gnu/:./lib/x86_64-linux-gnu/:./lib32/:./lib64/:../lib/:../lib/i386-linux-gnu/:../lib/x86_64-linux-gnu/:../lib32/:../lib64/:%s" - #define NEW_PATH "PATH=./bin/:./sbin/:./games/:../bin/:../sbin/:%s" - #define NEW_PYTHONPATH "PYTHONPATH=./share/pyshared/:%s" - #define NEW_XDG_DATA_DIRS "XDG_DATA_DIRS=./share/:%s" -@@ -138,8 +138,8 @@ - char *env, *new_env[7]; - - env = getenv("LD_LIBRARY_PATH") ?: ""; -- new_env[0] = malloc( strlen(NEW_LD_LIBRARY_PATH) + strlen(env) ); -- sprintf( new_env[0], NEW_LD_LIBRARY_PATH, env ); -+ new_env[0] = malloc( strlen(NEW_LD_LIBRARY_PATH) + strlen(optional) + strlen(env) ); -+ sprintf( new_env[0], NEW_LD_LIBRARY_PATH, optional, env ); - // printf( " using %s\n", new_env[0] ); - putenv( new_env[0] ); - -@@ -179,6 +179,11 @@ - // printf( " using %s\n", new_env[6] ); - putenv( new_env[6] ); - -+ checkrt(); +@@ -164,12 +164,16 @@ + char *old_env; + size_t length; + const char *format; ++ checkrt(usr_in_appdir); + + if (optional_ld_preload) + putenv(optional_ld_preload); -+ - /* Run */ - ret = execvp(executable, argv); -@@ -187,6 +192,9 @@ - die( "Error executing '%s'; return code: %d\n", executable, ret ); - } + /* https://docs.python.org/2/using/cmdline.html#envvar-PYTHONHOME */ + SET_NEW_ENV(new_pythonhome, appdir_s, "PYTHONHOME=%s/usr/", appdir); + + old_env = getenv("PATH") ?: ""; +- SET_NEW_ENV(new_path, appdir_s*5 + strlen(old_env), "PATH=%s/usr/bin/:%s/usr/sbin/:%s/usr/games/:%s/bin/:%s/sbin/:%s", appdir, appdir, appdir, appdir, appdir, old_env); ++ SET_NEW_ENV(new_path, appdir_s*5 + strlen(old_env), "PATH=%s%s/usr/bin/:%s/usr/sbin/:%s/usr/games/:%s/bin/:%s/sbin/:%s", optional, appdir, appdir, appdir, appdir, appdir, old_env); + + old_env = getenv("LD_LIBRARY_PATH") ?: ""; + SET_NEW_ENV(new_ld_library_path, appdir_s*10 + strlen(old_env), "LD_LIBRARY_PATH=%s/usr/lib/:%s/usr/lib/i386-linux-gnu/:%s/usr/lib/x86_64-linux-gnu/:%s/usr/lib32/:%s/usr/lib64/:%s/lib/:%s/lib/i386-linux-gnu/:%s/lib/x86_64-linux-gnu/:%s/lib32/:%s/lib64/:%s", appdir, appdir, appdir, appdir, appdir, appdir, appdir, appdir, appdir, appdir, old_env); +@@ -201,6 +205,9 @@ + if (ret == -1) + die("Error executing '%s': %s\n", exe, strerror(error)); + free(optional); + if (optional_ld_preload) + free(optional_ld_preload); - free(new_env[6]); - free(new_env[5]); - free(new_env[4]); + free(line); + free(desktop_file); + free(usr_in_appdir); diff --git a/Makefile b/Makefile index 2458df1..7af5a9b 100644 --- a/Makefile +++ b/Makefile @@ -21,5 +21,5 @@ AppRun_patched.c: AppRun.c patch -p1 --output $@ < AppRun.c.patch AppRun.c: - wget -c "https://raw.githubusercontent.com/AppImage/AppImageKit/master/AppRun.c" + wget -c "https://raw.githubusercontent.com/AppImage/AppImageKit/appimagetool/master/src/AppRun.c" diff --git a/checkrt.c b/checkrt.c index 0382fa6..40f9f52 100644 --- a/checkrt.c +++ b/checkrt.c @@ -41,14 +41,14 @@ ret = fscanf(f, "%s", sym); (void)ret; \ pclose(f); -#define CXXDIR "./optional/libstdc++" -#define GCCDIR "./optional/libgcc" -#define EXEC_SO "./optional/exec.so" +#define CXXDIR "optional/libstdc++" +#define GCCDIR "optional/libgcc" +#define EXEC_SO "optional/exec.so" char *optional = NULL; char *optional_ld_preload = NULL; -void checkrt() +void checkrt(char *usr_in_appdir) { int ret; FILE *f; @@ -58,8 +58,8 @@ void checkrt() char stdcxx_bundle_sym[LINE_SIZE], gcc_bundle_sym[LINE_SIZE]; int stdcxx_sys_ver=1, stdcxx_bundle_ver=0, gcc_sys_ver=1, gcc_bundle_ver=0; - char *stdcxx_bundle_lib = CXXDIR "/libstdc++.so.6"; - char *gcc_bundle_lib = GCCDIR "/libgcc_s.so.1"; + char *stdcxx_bundle_lib = "./" CXXDIR "/libstdc++.so.6"; + char *gcc_bundle_lib = "./" GCCDIR "/libgcc_s.so.1"; const char *format = "tr '\\0' '\\n' < '%s' | grep -e '%s' | tail -n1"; if (access(stdcxx_bundle_lib, F_OK) == 0) { @@ -94,6 +94,7 @@ void checkrt() int bundle_cxx = 0; int bundle_gcc = 0; + size_t len = strlen(usr_in_appdir); if (stdcxx_bundle_ver > stdcxx_sys_ver) bundle_cxx = 1; @@ -102,22 +103,31 @@ void checkrt() bundle_gcc = 1; if (bundle_cxx == 1 || bundle_gcc == 1) { - optional_ld_preload = malloc(strlen(EXEC_SO) + 12); - sprintf(optional_ld_preload, "LD_PRELOAD=" EXEC_SO); + len = strlen(EXEC_SO) + 12 + len; + optional_ld_preload = malloc(len); + sprintf(optional_ld_preload, "LD_PRELOAD=%s/" EXEC_SO, usr_in_appdir); + optional_ld_preload[len] = '\0'; } if (bundle_cxx == 1 && bundle_gcc == 0) { - optional = malloc(strlen(CXXDIR) + 2); - sprintf(optional, CXXDIR ":"); + len = strlen(CXXDIR) + 2 + len; + optional = malloc(len); + sprintf(optional, "%s/" CXXDIR ":", usr_in_appdir); } else if (bundle_cxx == 0 && bundle_gcc == 1) { - optional = malloc(strlen(GCCDIR) + 2); - sprintf(optional, GCCDIR ":"); + len = strlen(GCCDIR) + 2 + len; + optional = malloc(len); + sprintf(optional, "%s/" GCCDIR ":", usr_in_appdir); } else if (bundle_cxx == 1 && bundle_gcc == 1) { - optional = malloc(strlen(GCCDIR) + strlen(CXXDIR) + 3); - sprintf(optional, GCCDIR ":" CXXDIR ":"); + len = strlen(GCCDIR) + strlen(CXXDIR) + 4 + len*2; + optional = malloc(len); + sprintf(optional, "%s/" GCCDIR ":%s/" CXXDIR ":", usr_in_appdir, usr_in_appdir); } else { - optional = malloc(1); + len = 1; + optional = malloc(len); sprintf(optional, "%s", ""); } + optional[len] = '\0'; + + //printf("optional: %s\noptional_ld_preload: %s\n", optional, optional_ld_preload); } diff --git a/checkrt.h b/checkrt.h index 29f3365..aafe389 100644 --- a/checkrt.h +++ b/checkrt.h @@ -1,3 +1,3 @@ extern char *optional; extern char *optional_ld_preload; -extern void checkrt(void); +extern void checkrt(char *usr_in_appdir);