summaryrefslogtreecommitdiff
path: root/mailnews
diff options
context:
space:
mode:
authorMatt A. Tobin <email@mattatobin.com>2019-11-10 23:56:17 -0500
committerMatt A. Tobin <email@mattatobin.com>2019-11-10 23:56:17 -0500
commit4b217ebe51445711251e60f25ac509c2e4057815 (patch)
tree414d607fc81a77eafe7000b14082ae2b988a80a3 /mailnews
parentfa711799bfd8b2a8c745295f2d73a1c27daea302 (diff)
downloaduxp-4b217ebe51445711251e60f25ac509c2e4057815.tar.gz
Bug 1495698 - Fix hang when HTML signature references non-existent image.
Tag #1273
Diffstat (limited to 'mailnews')
-rw-r--r--mailnews/compose/src/nsMsgCompose.cpp71
-rw-r--r--mailnews/compose/src/nsMsgCompose.h16
2 files changed, 47 insertions, 40 deletions
diff --git a/mailnews/compose/src/nsMsgCompose.cpp b/mailnews/compose/src/nsMsgCompose.cpp
index 58340bffae..4ce8e8defc 100644
--- a/mailnews/compose/src/nsMsgCompose.cpp
+++ b/mailnews/compose/src/nsMsgCompose.cpp
@@ -4350,45 +4350,52 @@ nsMsgCompose::LoadDataFromFile(nsIFile *file, nsString &sigData,
* images loaded into the editor are available on send.
*/
nsresult
-nsMsgCompose::ReplaceFileURLs(nsAutoString &aData)
+nsMsgCompose::ReplaceFileURLs(nsString &aData)
{
int32_t fPos;
- int32_t offset = -1;
+ int32_t offset = -1; // We're using RFind(), so offset -1 is from the very right.
+
+ // XXX This code is rather incomplete since it looks for "file://" even
+ // outside tags.
while ((fPos = aData.RFind("file://", true, offset)) != kNotFound) {
- if (fPos != kNotFound && fPos > 0) {
- char16_t q = aData.CharAt(fPos - 1);
- bool quoted = (q == '"' || q == '\'');
- int32_t end = kNotFound;
- if (quoted) {
- end = aData.FindChar(q, fPos);
+ bool quoted = false;
+ char16_t q = 'x'; // initialise to anything to keep compilers happy.
+ if (fPos > 0) {
+ q = aData.CharAt(fPos - 1);
+ quoted = (q == '"' || q == '\'');
+ }
+ int32_t end = kNotFound;
+ if (quoted) {
+ end = aData.FindChar(q, fPos);
+ }
+ else {
+ int32_t spacePos = aData.FindChar(' ', fPos);
+ int32_t gtPos = aData.FindChar('>', fPos);
+ if (gtPos != kNotFound && spacePos != kNotFound) {
+ end = (spacePos < gtPos) ? spacePos : gtPos;
}
- else {
- int32_t spacePos = aData.FindChar(' ', fPos);
- int32_t gtPos = aData.FindChar('>', fPos);
- if (gtPos != kNotFound && spacePos != kNotFound) {
- end = (spacePos < gtPos) ? spacePos : gtPos;
- }
- else if (gtPos == kNotFound && spacePos != kNotFound) {
- end = spacePos;
- }
- else if (gtPos != kNotFound && spacePos == kNotFound) {
- end = gtPos;
- }
+ else if (gtPos == kNotFound && spacePos != kNotFound) {
+ end = spacePos;
}
- if (end == kNotFound) {
- break;
+ else if (gtPos != kNotFound && spacePos == kNotFound) {
+ end = gtPos;
}
- nsString fileURL;
- fileURL = Substring(aData, fPos, end - fPos);
- nsString dataURL;
- nsresult rv = DataURLForFileURL(fileURL, dataURL);
- // If this one failed, maybe because the file wasn't found,
- // continue to process the next one.
- if (NS_SUCCEEDED(rv)) {
- aData.Replace(fPos, end - fPos, dataURL);
- }
- offset = fPos - 1;
}
+ if (end == kNotFound) {
+ break;
+ }
+ nsString fileURL;
+ fileURL = Substring(aData, fPos, end - fPos);
+ nsString dataURL;
+ nsresult rv = DataURLForFileURL(fileURL, dataURL);
+ // If this one failed, maybe because the file wasn't found,
+ // continue to process the next one.
+ if (NS_SUCCEEDED(rv)) {
+ aData.Replace(fPos, end - fPos, dataURL);
+ }
+ if (fPos == 0)
+ break;
+ offset = fPos - 1;
}
return NS_OK;
}
diff --git a/mailnews/compose/src/nsMsgCompose.h b/mailnews/compose/src/nsMsgCompose.h
index 19609228f5..fb2f5a5944 100644
--- a/mailnews/compose/src/nsMsgCompose.h
+++ b/mailnews/compose/src/nsMsgCompose.h
@@ -33,7 +33,7 @@ struct nsMsgMailList;
class nsMsgCompose : public nsIMsgCompose, public nsSupportsWeakReference
{
- public:
+ public:
nsMsgCompose();
@@ -93,7 +93,7 @@ protected:
nsresult MoveToAboveQuote(void);
nsresult MoveToBeginningOfDocument(void);
nsresult MoveToEndOfDocument(void);
- nsresult ReplaceFileURLs(nsAutoString &sigData);
+ nsresult ReplaceFileURLs(nsString &sigData);
nsresult DataURLForFileURL(const nsAString &aFileURL, nsAString &aDataURL);
// 3 = To, Cc, Bcc
@@ -105,10 +105,10 @@ protected:
*/
nsresult LookupAddressBook(RecipientsArray &recipientList);
bool IsLastWindow();
-
+
// Helper function. Parameters are not checked.
bool mConvertStructs; // for TagConvertible
-
+
nsCOMPtr<nsIEditor> m_editor;
mozIDOMWindowProxy *m_window;
nsCOMPtr<nsIDocShell> mDocShell;
@@ -147,7 +147,7 @@ protected:
};
////////////////////////////////////////////////////////////////////////////////////
-// THIS IS THE CLASS THAT IS THE STREAM Listener OF THE HTML OUPUT
+// THIS IS THE CLASS THAT IS THE STREAM Listener OF THE HTML OUTPUT
// FROM LIBMIME. THIS IS FOR QUOTING
////////////////////////////////////////////////////////////////////////////////////
class QuotingOutputStreamListener : public nsIMsgQuotingOutputStreamListener
@@ -199,7 +199,7 @@ private:
};
////////////////////////////////////////////////////////////////////////////////////
-// This is the listener class for the send operation. We have to create this class
+// This is the listener class for the send operation. We have to create this class
// to listen for message send completion and eventually notify the caller
////////////////////////////////////////////////////////////////////////////////////
class nsMsgComposeSendListener : public nsIMsgComposeSendListener, public nsIMsgSendListener, public nsIMsgCopyServiceListener, public nsIWebProgressListener
@@ -215,10 +215,10 @@ public:
// nsIMsgSendListener interface
NS_DECL_NSIMSGSENDLISTENER
-
+
// nsIMsgCopyServiceListener interface
NS_DECL_NSIMSGCOPYSERVICELISTENER
-
+
// nsIWebProgressListener interface
NS_DECL_NSIWEBPROGRESSLISTENER