summaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authortc@google.com <tc@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-09-04 18:26:46 +0000
committertc@google.com <tc@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-09-04 18:26:46 +0000
commit261d17188f9c63f82ea326f510c2fddb477c9c97 (patch)
tree34b9264be8222e0c231d103f6901675f9e1906dc /net
parent7e101ed95c637df75d1f7bb27a18c5a66ed538f0 (diff)
downloadchromium_src-261d17188f9c63f82ea326f510c2fddb477c9c97.zip
chromium_src-261d17188f9c63f82ea326f510c2fddb477c9c97.tar.gz
chromium_src-261d17188f9c63f82ea326f510c2fddb477c9c97.tar.bz2
Fix a crash caused by a NULL FILETIME when creating ftp
directory listings. BUG=1350006 Review URL: http://codereview.chromium.org/419 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@1722 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r--net/base/net_util.cc10
-rw-r--r--net/base/net_util_unittest.cc35
2 files changed, 42 insertions, 3 deletions
diff --git a/net/base/net_util.cc b/net/base/net_util.cc
index df012a2..aa01f1f 100644
--- a/net/base/net_util.cc
+++ b/net/base/net_util.cc
@@ -819,9 +819,13 @@ std::string GetDirectoryListingEntry(const std::string& name,
result.append(",");
- Time time(Time::FromFileTime(*modified));
- string_escape::JavascriptDoubleQuote(base::TimeFormatShortDateAndTime(time),
- true, &result);
+ std::wstring modified_str;
+ // |modified| can be NULL in FTP listings.
+ if (modified) {
+ Time time(Time::FromFileTime(*modified));
+ modified_str = base::TimeFormatShortDateAndTime(time);
+ }
+ string_escape::JavascriptDoubleQuote(modified_str, true, &result);
result.append(");</script>\n");
diff --git a/net/base/net_util_unittest.cc b/net/base/net_util_unittest.cc
index 94017fc..954afad 100644
--- a/net/base/net_util_unittest.cc
+++ b/net/base/net_util_unittest.cc
@@ -698,3 +698,38 @@ TEST(NetUtilTest, GetSuggestedFilename) {
}
}
+// This is currently a windows specific function.
+#if defined(OS_WIN)
+namespace {
+
+struct GetDirectoryListingEntryCase {
+ const char* name;
+ DWORD file_attrib;
+ int64 filesize;
+ FILETIME* modified;
+ const char* expected;
+};
+
+} // namespace
+TEST(NetUtilTest, GetDirectoryListingEntry) {
+ const GetDirectoryListingEntryCase test_cases[] = {
+ {"Foo",
+ 0,
+ 10000,
+ NULL,
+ "<script>addRow(\"Foo\",\"Foo\",0,\"9.8 kB\",\"\");</script>\n"},
+ {"quo\"tes",
+ 0,
+ 10000,
+ NULL,
+ "<script>addRow(\"quo\\\"tes\",\"quo%22tes\",0,\"9.8 kB\",\"\");</script>\n"},
+ };
+
+ for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); ++i) {
+ const std::string results = net::GetDirectoryListingEntry(
+ test_cases[i].name, test_cases[i].file_attrib,
+ test_cases[i].filesize, test_cases[i].modified);
+ EXPECT_EQ(test_cases[i].expected, results);
+ }
+}
+#endif