Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(84)

Unified Diff: content/common/quarantine/quarantine_win.cc

Issue 2124373002: [PPAPI] Quarantine files that are writeable by a Pepper plugin. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@consolidate-file-metadata
Patch Set: Address comments. Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/common/quarantine/quarantine_win.cc
diff --git a/content/browser/download/quarantine_win.cc b/content/common/quarantine/quarantine_win.cc
similarity index 92%
rename from content/browser/download/quarantine_win.cc
rename to content/common/quarantine/quarantine_win.cc
index 3d41fc6798cf67ee7dd5c91db599e7b8ba4f46b1..91eecc75e02d415468a2c53a52e3610f94d28c2a 100644
--- a/content/browser/download/quarantine_win.cc
+++ b/content/common/quarantine/quarantine_win.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "content/browser/download/quarantine.h"
+#include "content/public/common/quarantine.h"
#include <windows.h>
@@ -13,6 +13,8 @@
#include <shobjidl.h>
#include <wininet.h>
+#include <vector>
+
#include "base/files/file_util.h"
#include "base/guid.h"
#include "base/logging.h"
@@ -20,6 +22,7 @@
#include "base/metrics/histogram_macros.h"
#include "base/metrics/sparse_histogram.h"
#include "base/strings/string_piece.h"
+#include "base/strings/string_split.h"
#include "base/strings/utf_string_conversions.h"
#include "base/threading/thread_restrictions.h"
#include "base/win/scoped_comptr.h"
@@ -67,16 +70,22 @@ bool ZoneIdentifierPresentForFile(const base::FilePath& path) {
// The zone identifier contents is expected to be:
// "[ZoneTransfer]\r\nZoneId=3\r\n". The actual ZoneId can be different. A
- // buffer of 16 bytes is sufficient for testing whether the contents start
- // with "[ZoneTransfer]".
- std::vector<char> zone_identifier_contents(16);
+ // buffer of 32 bytes is sufficient for verifying the contents.
+ std::vector<char> zone_identifier_contents_buffer(32);
DWORD actual_length = 0;
- if (!ReadFile(file.Get(), &zone_identifier_contents.front(),
- zone_identifier_contents.size(), &actual_length, NULL))
+ if (!ReadFile(file.Get(), &zone_identifier_contents_buffer.front(),
+ zone_identifier_contents_buffer.size(), &actual_length, NULL))
return false;
- base::StringPiece zone_identifier_string(&zone_identifier_contents.front(),
- actual_length);
- return zone_identifier_string.find("[ZoneTransfer]") == 0;
+ zone_identifier_contents_buffer.resize(actual_length);
+
+ std::string zone_identifier_contents(zone_identifier_contents_buffer.begin(),
+ zone_identifier_contents_buffer.end());
+
+ std::vector<base::StringPiece> lines =
+ base::SplitStringPiece(zone_identifier_contents, "\n",
+ base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
+ return lines.size() == 2 && lines[0] == "[ZoneTransfer]" &&
+ lines[1].find("ZoneId=") == 0;
}
void RecordAttachmentServicesSaveResult(const base::FilePath& file,
@@ -333,4 +342,10 @@ QuarantineFileResult QuarantineFile(const base::FilePath& file,
return QuarantineFileResult::OK;
}
+bool IsFileQuarantined(const base::FilePath& file,
+ const GURL& source_url,
+ const GURL& referrer_url) {
+ return ZoneIdentifierPresentForFile(file);
+}
+
} // namespace content
« no previous file with comments | « content/common/quarantine/quarantine_unittest.cc ('k') | content/common/quarantine/quarantine_win_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698