From 27ccb79edc3e3e313039b4718a0b25213e9089e9 Mon Sep 17 00:00:00 2001 From: lotodore Date: Sat, 10 May 2008 18:43:17 +0000 Subject: [PATCH] Added paranoia check before deleting file from the cache directory. --- src/net/common/clientstate.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/net/common/clientstate.cpp b/src/net/common/clientstate.cpp index 200502a7..069c089d 100644 --- a/src/net/common/clientstate.cpp +++ b/src/net/common/clientstate.cpp @@ -322,7 +322,6 @@ ClientStateSynchronizingServerList::Process(ClientThread &client) // No more checking needed as this was done before. md5ServerListPath /= context.GetServerListUrl().substr(context.GetServerListUrl().find_last_of('/') + 1) + ".md5"; - path serverListPath = change_extension(md5ServerListPath, ""); // Compare the md5 sums. string tmpMd5; @@ -346,8 +345,15 @@ ClientStateSynchronizingServerList::Process(ClientThread &client) else { // Download new server list. - remove(serverListPath); - client.SetState(ClientStateStartServerListDownload::Instance()); + // Paranoia check before removing the file, we do not want to delete wrong files. + path tmpPath(serverListPath); + if (path(context.GetCacheDir()) == tmpPath.remove_leaf()) + { + remove(serverListPath); + client.SetState(ClientStateStartServerListDownload::Instance()); + } + else + throw ClientException(__FILE__, __LINE__, ERR_SOCK_INVALID_SERVERLIST_URL, 0); } }