# HG changeset patch # User Tony Vroon # Date 1219752159 -3600 # Node ID d8998f6d5af56808b814436b3dd26f45fa26ee3c # Parent acfa92d9ff5e9c3fae364cd1c935ba322e7efc14 Prevent infinite loops on .rar files in modplug plugin, patch by Barro (bugzilla 34). diff -r acfa92d9ff5e -r d8998f6d5af5 src/modplug/archive/arch_rar.cxx --- a/src/modplug/archive/arch_rar.cxx Wed Aug 20 22:42:30 2008 +0300 +++ b/src/modplug/archive/arch_rar.cxx Tue Aug 26 13:02:39 2008 +0100 @@ -135,11 +135,10 @@ bool arch_Rar::ContainsMod(const string& aFileName) { //check if file exists + const uint32 LBUFFER_SIZE = 350; string lName; int lFileDesc = open(aFileName.c_str(), O_RDONLY); - char lBuffer[350]; - uint32 lLength; - uint32 lCount; + char lBuffer[LBUFFER_SIZE]; if(lFileDesc == -1) return false; @@ -167,14 +166,15 @@ bool eof = false; while(!eof) { - if(fgets(lBuffer, 350, f) || f <= 0) - if(f <= 0) - break; - if (strlen(lBuffer) > 1) - lBuffer[strlen(lBuffer)-1] = 0; + if(fgets(lBuffer, LBUFFER_SIZE, f) == NULL) + break; // End of file or read error + uint32 lLength = strnlen(lBuffer, LBUFFER_SIZE); + if (lLength > 1) + lBuffer[lLength-1] = 0; - lLength = strlen(lBuffer); - lCount = 0; + uint32 lCount = 0; + // Remove non-filename related data from the end of the each + // filename line (9 fields separated by a space) for(uint32 i = lLength - 1; i > 0; i--) { if(lBuffer[i] == ' ') @@ -197,6 +197,6 @@ } } - pclose(f); + pclose(f); return false; }