Skip to content

Commit 8bbf694

Browse files
authored
Merge pull request #1103 from omegacoleman/fix-appstream-crash
fix #856: block envs set in resources/AppRun when invoking appstream utilities
2 parents 61d07b2 + b181fc4 commit 8bbf694

File tree

1 file changed

+49
-4
lines changed

1 file changed

+49
-4
lines changed

src/appimagetool.c

+49-4
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,41 @@ bool readFile(char* filename, int* size, char** buffer) {
457457
return TRUE;
458458
}
459459

460+
/* run a command outside the current appimage, block environs like LD_LIBRARY_PATH */
461+
int run_external(const char *filename, char *const argv []) {
462+
int pid = fork();
463+
if (pid < 0) {
464+
g_print("run_external: fork failed");
465+
// fork failed
466+
exit(1);
467+
} else if (pid == 0) {
468+
// blocks env defined in resources/AppRun
469+
unsetenv("LD_LIBRARY_PATH");
470+
unsetenv("PYTHONPATH");
471+
unsetenv("XDG_DATA_DIRS");
472+
unsetenv("PERLLIB");
473+
unsetenv("GSETTINGS_SCHEMA_DIR");
474+
unsetenv("QT_PLUGIN_PATH");
475+
// runs command
476+
execv(filename, argv);
477+
// execv(3) returns, indicating error
478+
g_print("run_external: subprocess execv(3) got error %s", g_strerror(errno));
479+
exit(1);
480+
} else {
481+
int wstatus;
482+
if (waitpid(pid, &wstatus, 0) == -1) {
483+
g_print("run_external: wait failed");
484+
return -1;
485+
}
486+
if (WIFEXITED(wstatus) && (WEXITSTATUS(wstatus) == 0)) {
487+
return 0;
488+
} else {
489+
g_print("run_external: subprocess exited with status %d", WEXITSTATUS(wstatus));
490+
return 1;
491+
}
492+
}
493+
}
494+
460495
// #####################################################################
461496

462497
static GOptionEntry entries[] =
@@ -794,19 +829,29 @@ main (int argc, char *argv[])
794829
fprintf (stderr, "AppStream upstream metadata found in usr/share/metainfo/%s\n", application_id);
795830
/* Use ximion's appstreamcli to make sure that desktop file and appdata match together */
796831
if(g_find_program_in_path ("appstreamcli")) {
797-
sprintf (command, "%s validate-tree %s", g_find_program_in_path ("appstreamcli"), source);
832+
char *args[] = {
833+
"appstreamcli",
834+
"validate-tree",
835+
source,
836+
NULL
837+
};
798838
g_print("Trying to validate AppStream information with the appstreamcli tool\n");
799839
g_print("In case of issues, please refer to https://github.com/ximion/appstream\n");
800-
int ret = system(command);
840+
int ret = run_external(g_find_program_in_path ("appstreamcli"), args);
801841
if (ret != 0)
802842
die("Failed to validate AppStream information with appstreamcli");
803843
}
804844
/* It seems that hughsie's appstream-util does additional validations */
805845
if(g_find_program_in_path ("appstream-util")) {
806-
sprintf (command, "%s validate-relax %s", g_find_program_in_path ("appstream-util"), appdata_path);
846+
char *args[] = {
847+
"appstream-util",
848+
"validate-relax",
849+
appdata_path,
850+
NULL
851+
};
807852
g_print("Trying to validate AppStream information with the appstream-util tool\n");
808853
g_print("In case of issues, please refer to https://github.com/hughsie/appstream-glib\n");
809-
int ret = system(command);
854+
int ret = run_external(g_find_program_in_path ("appstream-util"), args);
810855
if (ret != 0)
811856
die("Failed to validate AppStream information with appstream-util");
812857
}

0 commit comments

Comments
 (0)