Skip to content

Commit 23ca6bb

Browse files
committed
Implement absolute path calculation with proper error checks
1 parent 6917f75 commit 23ca6bb

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

src/runtime.c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -606,13 +606,22 @@ int main(int argc, char *argv[]) {
606606
int length;
607607
char fullpath[PATH_MAX];
608608

609-
if(getenv("TARGET_APPIMAGE") == NULL){
609+
if(getenv("TARGET_APPIMAGE") == NULL) {
610610
// If we are operating on this file itself
611-
length = readlink(appimage_path, fullpath, sizeof(fullpath));
612-
fullpath[length] = '\0';
611+
ssize_t len = readlink(appimage_path, fullpath, sizeof(fullpath));
612+
if (len < 0) {
613+
perror("Failed to obtain absolute path");
614+
exit(EXIT_EXECERROR);
615+
}
616+
fullpath[len] = '\0';
613617
} else {
614-
// If we are operating on a different AppImage than this file
615-
sprintf(fullpath, "%s", appimage_path); // TODO: Make absolute
618+
char* abspath = realpath(appimage_path, NULL);
619+
if (abspath == NULL) {
620+
perror("Failed to obtain absolute path");
621+
exit(EXIT_EXECERROR);
622+
}
623+
strcpy(fullpath, abspath);
624+
free(abspath);
616625
}
617626

618627
if (arg && strcmp(arg, "appimage-extract-and-run") == 0) {

0 commit comments

Comments
 (0)