From 261d17188f9c63f82ea326f510c2fddb477c9c97 Mon Sep 17 00:00:00 2001 From: "tc@google.com" Date: Thu, 4 Sep 2008 18:26:46 +0000 Subject: 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 --- net/base/net_util.cc | 10 +++++++--- net/base/net_util_unittest.cc | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 3 deletions(-) (limited to 'net') 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(");\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, + "\n"}, + {"quo\"tes", + 0, + 10000, + NULL, + "\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 -- cgit v1.1