diff options
author | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-21 18:33:54 +0000 |
---|---|---|
committer | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-21 18:33:54 +0000 |
commit | 00738b00b20f664a1f5741abbdfc41436529e3dd (patch) | |
tree | a3799a97191bbdcaf993452512b4ec79007751f9 /app | |
parent | 724df9934be5e51be3b46b2ecde4802eb25d37d6 (diff) | |
download | chromium_src-00738b00b20f664a1f5741abbdfc41436529e3dd.zip chromium_src-00738b00b20f664a1f5741abbdfc41436529e3dd.tar.gz chromium_src-00738b00b20f664a1f5741abbdfc41436529e3dd.tar.bz2 |
[GTK] fix wraparound error in clipboard.
0U - 1 = pain
BUG=56298
TEST=see bug
Review URL: http://codereview.chromium.org/3394011
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@60079 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'app')
-rw-r--r-- | app/clipboard/clipboard.h | 1 | ||||
-rw-r--r-- | app/clipboard/clipboard_linux.cc | 2 | ||||
-rw-r--r-- | app/clipboard/clipboard_unittest.cc | 20 |
3 files changed, 22 insertions, 1 deletions
diff --git a/app/clipboard/clipboard.h b/app/clipboard/clipboard.h index 570bec9..47a68f2 100644 --- a/app/clipboard/clipboard.h +++ b/app/clipboard/clipboard.h @@ -187,6 +187,7 @@ class Clipboard { private: FRIEND_TEST_ALL_PREFIXES(ClipboardTest, SharedBitmapTest); + FRIEND_TEST_ALL_PREFIXES(ClipboardTest, EmptyHTMLTest); void DispatchObject(ObjectType type, const ObjectMapParams& params); diff --git a/app/clipboard/clipboard_linux.cc b/app/clipboard/clipboard_linux.cc index 708e303..7fa633e 100644 --- a/app/clipboard/clipboard_linux.cc +++ b/app/clipboard/clipboard_linux.cc @@ -350,7 +350,7 @@ void Clipboard::ReadHTML(Clipboard::Buffer buffer, string16* markup, } // If there is a terminating NULL, drop it. - if (markup->at(markup->length() - 1) == '\0') + if (!markup->empty() && markup->at(markup->length() - 1) == '\0') markup->resize(markup->length() - 1); gtk_selection_data_free(data); diff --git a/app/clipboard/clipboard_unittest.cc b/app/clipboard/clipboard_unittest.cc index ef82104..abc3db5 100644 --- a/app/clipboard/clipboard_unittest.cc +++ b/app/clipboard/clipboard_unittest.cc @@ -140,6 +140,26 @@ TEST_F(ClipboardTest, TrickyHTMLTest) { #endif // defined(OS_WIN) } +#if defined(OS_LINUX) +// Regression test for crbug.com/56298 (pasting empty HTML crashes Linux). +TEST_F(ClipboardTest, EmptyHTMLTest) { + Clipboard clipboard; + // ScopedClipboardWriter doesn't let us write empty data to the clipboard. + clipboard.clipboard_data_ = new Clipboard::TargetMap(); + // The 1 is so the compiler doesn't warn about allocating an empty array. + char* empty = new char[1]; + clipboard.InsertMapping("text/html", empty, 0U); + clipboard.SetGtkClipboard(); + + EXPECT_TRUE(clipboard.IsFormatAvailable(Clipboard::GetHtmlFormatType(), + Clipboard::BUFFER_STANDARD)); + string16 markup_result; + std::string url_result; + clipboard.ReadHTML(Clipboard::BUFFER_STANDARD, &markup_result, &url_result); + EXPECT_TRUE(ClipboardContentsIsExpected(string16(), markup_result)); +} +#endif + // TODO(estade): Port the following test (decide what target we use for urls) #if !defined(OS_POSIX) || defined(OS_MACOSX) TEST_F(ClipboardTest, BookmarkTest) { |