diff options
author | Christian Persch <chpe@cvs.gnome.org> | 2006-01-30 20:21:27 +0000 |
---|---|---|
committer | Christian Persch <chpe@src.gnome.org> | 2006-01-30 20:21:27 +0000 |
commit | 597cf1e5a8c810f2f88472d6f5c7f288f855b48c (patch) | |
tree | 95d8eb1c530272c1c9376eac807bf7edf47855f9 /embed | |
parent | 3abdd2244d6ed39f940a50e4fd015bff2e1cb980 (diff) | |
download | epiphany-597cf1e5a8c810f2f88472d6f5c7f288f855b48c.tar.gz |
Truncate URI and title strings. Bug #329160.
2006-01-30 Christian Persch <chpe@cvs.gnome.org>
* embed/mozilla/GlobalHistory.cpp:
Truncate URI and title strings. Bug #329160.
Diffstat (limited to 'embed')
-rw-r--r-- | embed/mozilla/GlobalHistory.cpp | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/embed/mozilla/GlobalHistory.cpp b/embed/mozilla/GlobalHistory.cpp index 27d71b9ab..f66229444 100644 --- a/embed/mozilla/GlobalHistory.cpp +++ b/embed/mozilla/GlobalHistory.cpp @@ -32,6 +32,9 @@ #include <nsEmbedString.h> #define MOZILLA_INTERNAL_API 1 +#define MAX_TITLE_LENGTH 2048 +#define MAX_URL_LENGTH 16384 + NS_IMPL_ISUPPORTS1 (MozGlobalHistory, nsIGlobalHistory2) MozGlobalHistory::MozGlobalHistory () @@ -91,6 +94,8 @@ NS_IMETHODIMP MozGlobalHistory::AddURI(nsIURI *aURI, PRBool aRedirect, PRBool aT rv = aURI->GetSpec(spec); NS_ENSURE_TRUE (NS_SUCCEEDED(rv) && spec.Length(), rv); + if (spec.Length () > MAX_URL_LENGTH) return NS_OK; + ephy_history_add_page (mGlobalHistory, spec.get()); return NS_OK; @@ -101,9 +106,13 @@ NS_IMETHODIMP MozGlobalHistory::IsVisited(nsIURI *aURI, PRBool *_retval) { NS_ENSURE_ARG (aURI); + *_retval = PR_FALSE; + nsEmbedCString spec; aURI->GetSpec(spec); + if (spec.Length () > MAX_URL_LENGTH) return NS_OK; + *_retval = ephy_history_is_page_visited (mGlobalHistory, spec.get()); return NS_OK; @@ -114,14 +123,24 @@ NS_IMETHODIMP MozGlobalHistory::SetPageTitle(nsIURI *aURI, const nsAString & aTi { NS_ENSURE_ARG (aURI); - nsEmbedCString title; - NS_UTF16ToCString (nsEmbedString (aTitle), - NS_CSTRING_ENCODING_UTF8, title); - nsEmbedCString spec; aURI->GetSpec(spec); + + if (spec.Length () > MAX_URL_LENGTH) return NS_OK; - ephy_history_set_page_title (mGlobalHistory, spec.get(), title.get()); + /* This depends on the assumption that + * typeof(PRUnichar) == typeof (gunichar2) == uint16, + * which should be pretty safe. + */ + glong n_read = 0, n_written = 0; + char *converted = g_utf16_to_utf8 ((gunichar2*) uTitle.get(), MAX_TITLE_LENGTH, + &n_read, &n_written, NULL); + /* FIXME loop from the end while !g_unichar_isspace (char)? */ + if (converted == NULL) return NS_OK; + + ephy_history_set_page_title (mGlobalHistory, spec.get(), converted); + + g_free (converted); return NS_OK; } |