Skip to content

Commit

Permalink
filesystem: fix recursive basedir possible cyclic dependency when def…
Browse files Browse the repository at this point in the history
…ault game directory uses a basedir that's base directory is undefined

That could happen when default game directory depends on base directory that don't have gameinfo.txt.
Because all game directories with liblist.gam automatically have dependency on default game directory, it causes cyclic dependency.
  • Loading branch information
a1batross committed Jan 29, 2025
1 parent 8cd9988 commit 2457ecf
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions filesystem/filesystem.c
Original file line number Diff line number Diff line change
Expand Up @@ -1199,11 +1199,11 @@ void FS_AddGameHierarchy( const char *dir, uint flags )
qboolean isGameDir = flags & FS_GAMEDIR_PATH;
char buf[MAX_VA_STRING];

GI->added = true;

if( !COM_CheckString( dir ))
return;

Con_Printf( "%s( %s )\n", __func__, dir );

// add the common game directory

// recursive gamedirs
Expand All @@ -1214,12 +1214,21 @@ void FS_AddGameHierarchy( const char *dir, uint flags )
{
dir = FI.games[i]->gamefolder; // fixup directory case

if( FI.games[i]->added ) // already added, refusing
break;

// don't add our game directory as base dir to prevent cyclic dependency
if( Q_stricmp( FI.games[i]->basedir, GI->gamefolder ))
break;

// don't add directory which basedir is equal to this gamefolder to prevent
// endless loop
if( Q_stricmp( FI.games[i]->basedir, FI.games[i]->gamefolder ))
break;

Con_Reportf( "%s: adding recursive basedir %s\n", __func__, FI.games[i]->basedir );
if( !FI.games[i]->added && Q_stricmp( FI.games[i]->gamefolder, FI.games[i]->basedir ))
{
FI.games[i]->added = true;
FS_AddGameHierarchy( FI.games[i]->basedir, flags & (~FS_GAMEDIR_PATH) );
}
FI.games[i]->added = true;
FS_AddGameHierarchy( FI.games[i]->basedir, flags & (~FS_GAMEDIR_PATH));
break;
}
}
Expand Down Expand Up @@ -1276,6 +1285,8 @@ void FS_Rescan( void )
FS_AddGameHierarchy( GI->basedir, 0 );
if( Q_stricmp( GI->basedir, GI->falldir ) && Q_stricmp( GI->gamefolder, GI->falldir ))
FS_AddGameHierarchy( GI->falldir, 0 );

GI->added = true;
FS_AddGameHierarchy( GI->gamefolder, FS_GAMEDIR_PATH );
}

Expand Down

0 comments on commit 2457ecf

Please sign in to comment.