Skip to content

Commit a98643b

Browse files
committed
Extract TARGET_APPIMAGE variable, initialize argv0_path to avoid strcpy
1 parent 3b1499f commit a98643b

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/runtime/runtime.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1332,7 +1332,7 @@ char* appimage_hexlify(const char* bytes, const size_t numBytes) {
13321332
}
13331333

13341334
int main(int argc, char* argv[]) {
1335-
char appimage_path[PATH_MAX];
1335+
char appimage_path[PATH_MAX] = "/proc/self/exe";
13361336
char argv0_path[PATH_MAX];
13371337
char* arg;
13381338

@@ -1342,16 +1342,16 @@ int main(int argc, char* argv[]) {
13421342
* change any time. Do not rely on it being present. We might even limit this
13431343
* functionality specifically for builds used by appimaged.
13441344
*/
1345-
if (getenv("TARGET_APPIMAGE") == NULL) {
1346-
strcpy(appimage_path, "/proc/self/exe");
1345+
const char* const TARGET_APPIMAGE = getenv("TARGET_APPIMAGE");
1346+
if (TARGET_APPIMAGE == NULL) {
13471347
char *res = memccpy(argv0_path, argv[0], '\0', sizeof(argv0_path));
13481348
if (res == NULL) {
13491349
fprintf(stderr, "Program name too big\n");
13501350
exit(EXIT_EXECERROR);
13511351
}
13521352
} else {
1353-
char *res1 = memccpy(appimage_path, getenv("TARGET_APPIMAGE"), '\0', sizeof(appimage_path));
1354-
char *res2 = memccpy(argv0_path, getenv("TARGET_APPIMAGE"), '\0', sizeof(argv0_path));
1353+
char *res1 = memccpy(appimage_path, TARGET_APPIMAGE, '\0', sizeof(appimage_path));
1354+
char *res2 = memccpy(argv0_path, TARGET_APPIMAGE, '\0', sizeof(argv0_path));
13551355
if (res1 == NULL || res2 == NULL) {
13561356
fprintf(stderr, "TARGET_APPIMAGE environment variable too big\n");
13571357
exit(EXIT_EXECERROR);

0 commit comments

Comments
 (0)