@@ -1482,10 +1482,18 @@ int main(int argc, char* argv[]) {
1482
1482
*/
1483
1483
if (getenv ("TARGET_APPIMAGE" ) == NULL ) {
1484
1484
strcpy (appimage_path , "/proc/self/exe" );
1485
- strcpy (argv0_path , argv [0 ]);
1485
+ char * res = memccpy (argv0_path , argv [0 ], '\0' , sizeof (argv0_path ));
1486
+ if (res == NULL ) {
1487
+ fprintf (stderr , "Program name too big\n" );
1488
+ exit (EXIT_EXECERROR );
1489
+ }
1486
1490
} else {
1487
- strcpy (appimage_path , getenv ("TARGET_APPIMAGE" ));
1488
- strcpy (argv0_path , getenv ("TARGET_APPIMAGE" ));
1491
+ char * res1 = memccpy (appimage_path , getenv ("TARGET_APPIMAGE" ), '\0' , sizeof (appimage_path ));
1492
+ char * res2 = memccpy (argv0_path , getenv ("TARGET_APPIMAGE" ), '\0' , sizeof (argv0_path ));
1493
+ if (res1 == NULL || res2 == NULL ) {
1494
+ fprintf (stderr , "TARGET_APPIMAGE environment variable too big\n" );
1495
+ exit (EXIT_EXECERROR );
1496
+ }
1489
1497
}
1490
1498
1491
1499
// temporary directories are required in a few places
@@ -1494,8 +1502,13 @@ int main(int argc, char* argv[]) {
1494
1502
1495
1503
{
1496
1504
const char * const TMPDIR = getenv ("TMPDIR" );
1497
- if (TMPDIR != NULL )
1498
- strcpy (temp_base , getenv ("TMPDIR" ));
1505
+ if (TMPDIR != NULL ) {
1506
+ char * res = memccpy (temp_base , TMPDIR , '\0' , sizeof (temp_base ));
1507
+ if (res == NULL ) {
1508
+ fprintf (stderr , "TMPDIR environemnt variable too big\n" );
1509
+ exit (EXIT_EXECERROR );
1510
+ }
1511
+ }
1499
1512
}
1500
1513
1501
1514
fs_offset = appimage_get_elf_size (appimage_path );
0 commit comments