From 1bf65b9fb9f549d530a8575d2e39d0db007f4226 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Mon, 5 Apr 2004 03:09:58 +0000 Subject: [PATCH] Fix crashes when song paths begin with "../". --- stepmania/src/Song.cpp | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/stepmania/src/Song.cpp b/stepmania/src/Song.cpp index 28ec06510d..5fa12c4b07 100644 --- a/stepmania/src/Song.cpp +++ b/stepmania/src/Song.cpp @@ -443,12 +443,19 @@ static bool ImageIsLoadable( const CString &sPath ) } */ /* Fix up song paths. If there's a leading "./", be sure to keep it: it's - * a signal that the path is from the root directory, not the song directory. */ -void FixupPath( CString &path ) + * a signal that the path is from the root directory, not the song directory. + * Other than a leading "./", song paths must never contain "." or "..". */ +void FixupPath( CString &path, const CString &sSongPath ) { /* Replace backslashes with slashes in all paths. */ FixSlashesInPlace( path ); + if( path.Left(3) == "../" ) + { + /* The path begins with "../". Resolve it wrt. the song directory. */ + path = sSongPath + "/" + path; + } + CollapsePath( path ); /* Many imported files contain erroneous whitespace before or after @@ -586,12 +593,13 @@ void Song::TidyUpData() CHECKPOINT_M( "Looking for images..." ); - FixupPath( m_sSongDir ); - FixupPath( m_sMusicFile ); - FixupPath( m_sBannerFile ); - FixupPath( m_sLyricsFile ); - FixupPath( m_sBackgroundFile ); - FixupPath( m_sCDTitleFile ); + ASSERT_M( m_sSongDir.Left(3) != "../", m_sSongDir ); /* meaningless */ + FixupPath( m_sSongDir, "" ); + FixupPath( m_sMusicFile, m_sSongDir ); + FixupPath( m_sBannerFile, m_sSongDir ); + FixupPath( m_sLyricsFile, m_sSongDir ); + FixupPath( m_sBackgroundFile, m_sSongDir ); + FixupPath( m_sCDTitleFile, m_sSongDir ); // // First, check the file name for hints.