From 1609bb2f67860ce93f3a4ad14821257c923e7975 Mon Sep 17 00:00:00 2001 From: Owen Date: Mon, 17 Dec 2018 13:45:33 -0500 Subject: [PATCH] Mail: Fix infinite loop in FindURL. Fixes #14746. Signed-off-by: Augustin Cavalier One minor change from owenca's original patch: we can't return immediately if urlString is NULL, as the caller probably wants the urlLength. --- src/apps/mail/Content.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/apps/mail/Content.cpp b/src/apps/mail/Content.cpp index 6775b6c527..017c9cab3c 100644 --- a/src/apps/mail/Content.cpp +++ b/src/apps/mail/Content.cpp @@ -314,14 +314,17 @@ FindURL(const BString& string, int32 startIndex, int32& urlPos, urlLength = strcspn(str, " \t<>)\"\\,\r\n"); // filter out some punctuation marks if they are the last character - char suffix = str[urlLength - 1]; - while (suffix == '.' - || suffix == ',' - || suffix == '?' - || suffix == '!' - || suffix == ':' - || suffix == ';') + while (urlLength > 0) { + char suffix = str[urlLength - 1]; + if (suffix != '.' + && suffix != ',' + && suffix != '?' + && suffix != '!' + && suffix != ':' + && suffix != ';') + break; urlLength--; + } if (urlString != NULL) *urlString = BString(string.String() + urlPos, urlLength);