From ffac161fc2309f15343a6251840a7023027ab0e5 Mon Sep 17 00:00:00 2001 From: Szymon Tokarz Date: Sat, 21 Dec 2013 12:03:28 +0000 Subject: Association Manager - try to fix wired logic at CleanupRegTreeBackupSettings() - fix pszClassName use after free - fix cleanup if more than one class exists into bak_ ppszSettings git-svn-id: http://svn.miranda-ng.org/main/trunk@7315 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/AssocMgr/src/reg.cpp | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) (limited to 'plugins/AssocMgr') diff --git a/plugins/AssocMgr/src/reg.cpp b/plugins/AssocMgr/src/reg.cpp index 8936ab14e2..9737094980 100644 --- a/plugins/AssocMgr/src/reg.cpp +++ b/plugins/AssocMgr/src/reg.cpp @@ -546,20 +546,27 @@ void CleanupRegTreeBackupSettings(void) char *pszBuf = strchr(pszClassName,'\\'); if (pszBuf != NULL) { *pszBuf = '\0'; + /* remove others in list with same class name */ - for(int j=i; j < nSettingsCount; ++j) { - pszBuf = strchr(&ppszSettings[j][4],'\\'); - if (pszBuf != NULL) *pszBuf='\0'; - if ( lstrcmpA(pszClassName, &ppszSettings[j][4])) continue; - - mir_free(ppszSettings[j]); - MoveMemory(&ppszSettings[j],&ppszSettings[j+1],((--nSettingsCount)-j)*sizeof(TCHAR*)); - --j; /* reiterate current index */ + if(i < nSettingsCount-1){ + for(int j=i+1; j < nSettingsCount; ++j) { + pszBuf = strchr(&ppszSettings[j][4],'\\'); + if (pszBuf != NULL) *pszBuf='\0'; + if (lstrcmpA(pszClassName, &ppszSettings[j][4])){ + if (pszBuf != NULL) *pszBuf='\\'; + continue; + } + + mir_free(ppszSettings[j]); + MoveMemory(&ppszSettings[j], &ppszSettings[j+1], ((--nSettingsCount)-j) * sizeof(char*)); + --j; /* reiterate current index */ + } } + /* no longer registered? */ - if ( !IsRegisteredAssocItem(pszClassName)) { + if (!IsRegisteredAssocItem(pszClassName)) { char *pszFileExt; - if ( IsFileClassName(pszClassName, &pszFileExt)) + if (IsFileClassName(pszClassName, &pszFileExt)) RemoveRegFileExt(pszFileExt, pszClassName); else RemoveRegClass(pszClassName); -- cgit v1.2.3