From 33f7552be5047fd19dd716c42eb36dc707f16334 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Sat, 24 Dec 2005 02:37:06 +0000 Subject: [PATCH] fix potential crash if QueryDosDevice fails, or returns more data than expected --- .../MemoryCard/MemoryCardDriverThreaded_Windows.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded_Windows.cpp b/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded_Windows.cpp index d13ae5e303..35d26612db 100644 --- a/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded_Windows.cpp +++ b/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded_Windows.cpp @@ -53,9 +53,18 @@ static bool IsFloppyDrive( const CString &sDrive ) { char szBuf[1024]; - QueryDosDevice( sDrive, szBuf, 1024 ); + int iRet = QueryDosDevice( sDrive, szBuf, 1024 ); + if( iRet == 0 ) + { + LOG->Warn( werr_ssprintf(GetLastError(), "QueryDosDevice(%s)", sDrive.c_str()) ); + return false; + } - char *p = szBuf; + // Make sure szBuf is terminated with two nulls. This only may be needed if the buffer filled. + szBuf[iRet-2] = 0; + szBuf[iRet-1] = 0; + + const char *p = szBuf; while( *p ) { if( BeginsWith(p, "\\Device\\Floppy") )