@@ -1344,10 +1344,18 @@ int main(int argc, char* argv[]) {
1344
1344
*/
1345
1345
if (getenv ("TARGET_APPIMAGE" ) == NULL ) {
1346
1346
strcpy (appimage_path , "/proc/self/exe" );
1347
- strcpy (argv0_path , argv [0 ]);
1347
+ char * res = memccpy (argv0_path , argv [0 ], '\0' , sizeof (argv0_path ));
1348
+ if (res == NULL ) {
1349
+ fprintf (stderr , "Program name too big\n" );
1350
+ exit (EXIT_EXECERROR );
1351
+ }
1348
1352
} else {
1349
- strcpy (appimage_path , getenv ("TARGET_APPIMAGE" ));
1350
- strcpy (argv0_path , getenv ("TARGET_APPIMAGE" ));
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 ));
1355
+ if (res1 == NULL || res2 == NULL ) {
1356
+ fprintf (stderr , "TARGET_APPIMAGE environment variable too big\n" );
1357
+ exit (EXIT_EXECERROR );
1358
+ }
1351
1359
}
1352
1360
1353
1361
// temporary directories are required in a few places
@@ -1356,8 +1364,13 @@ int main(int argc, char* argv[]) {
1356
1364
1357
1365
{
1358
1366
const char * const TMPDIR = getenv ("TMPDIR" );
1359
- if (TMPDIR != NULL )
1360
- strcpy (temp_base , getenv ("TMPDIR" ));
1367
+ if (TMPDIR != NULL ) {
1368
+ char * res = memccpy (temp_base , TMPDIR , '\0' , sizeof (temp_base ));
1369
+ if (res == NULL ) {
1370
+ fprintf (stderr , "TMPDIR environemnt variable too big\n" );
1371
+ exit (EXIT_EXECERROR );
1372
+ }
1373
+ }
1361
1374
}
1362
1375
1363
1376
fs_offset = appimage_get_elf_size (appimage_path );
0 commit comments