summaryrefslogtreecommitdiff
path: root/indra/llcommon/lluriparser.cpp
diff options
context:
space:
mode:
authorAndrey Lihatskiy <alihatskiy@productengine.com>2021-04-30 03:04:47 +0300
committerAndrey Lihatskiy <alihatskiy@productengine.com>2021-04-30 03:04:47 +0300
commit0fa5fc47a2069a2c151536baa917b9c6978480e4 (patch)
tree2964096f28a6a5e7f08e5a0aa83f2ffe76d42421 /indra/llcommon/lluriparser.cpp
parent498b72aacd6d10dfcd4f15e1d16532dc138f0461 (diff)
parentce65bc2f13409d75dbc6502c970030cc5ed2e5ad (diff)
Merge branch 'master' into DRTVWR-527-maint
Diffstat (limited to 'indra/llcommon/lluriparser.cpp')
-rw-r--r--indra/llcommon/lluriparser.cpp87
1 files changed, 64 insertions, 23 deletions
diff --git a/indra/llcommon/lluriparser.cpp b/indra/llcommon/lluriparser.cpp
index c275b90120..e4f229dd16 100644
--- a/indra/llcommon/lluriparser.cpp
+++ b/indra/llcommon/lluriparser.cpp
@@ -29,10 +29,13 @@
#include "linden_common.h"
#include "lluriparser.h"
+#if LL_DARWIN
+#include <signal.h>
+#include <setjmp.h>
+#endif
+
LLUriParser::LLUriParser(const std::string& u) : mTmpScheme(false), mNormalizedTmp(false), mRes(0)
{
- mState.uri = &mUri;
-
if (u.find("://") == std::string::npos)
{
mNormalizedUri = "http://";
@@ -51,7 +54,7 @@ LLUriParser::~LLUriParser()
S32 LLUriParser::parse()
{
- mRes = uriParseUriA(&mState, mNormalizedUri.c_str());
+ mRes = uriParseSingleUriA(&mUri, mNormalizedUri.c_str(), NULL);
return mRes;
}
@@ -158,31 +161,69 @@ void LLUriParser::extractParts()
}
}
+#if LL_DARWIN
+typedef void(*sighandler_t)(int);
+jmp_buf return_to_normalize;
+void uri_signal_handler(int signal)
+{
+ // Apparently signal handler throwing an exception doesn't work.
+ // This is ugly and unsafe due to not unwinding content of uriparser library,
+ // but unless we have a way to catch this as NSexception, jump appears to be the only option.
+ longjmp(return_to_normalize, 1 /*setjmp will return this value*/);
+}
+#endif
+
S32 LLUriParser::normalize()
{
mNormalizedTmp = mTmpScheme;
if (!mRes)
{
- mRes = uriNormalizeSyntaxExA(&mUri, URI_NORMALIZE_SCHEME | URI_NORMALIZE_HOST);
-
- if (!mRes)
- {
- S32 chars_required;
- mRes = uriToStringCharsRequiredA(&mUri, &chars_required);
-
- if (!mRes)
- {
- chars_required++;
- std::vector<char> label_buf(chars_required);
- mRes = uriToStringA(&label_buf[0], &mUri, chars_required, NULL);
-
- if (!mRes)
- {
- mNormalizedUri = &label_buf[mTmpScheme ? 7 : 0];
- mTmpScheme = false;
- }
- }
- }
+#if LL_DARWIN
+ sighandler_t last_handler;
+ last_handler = signal(SIGILL, &uri_signal_handler); // illegal instruction
+ if (setjmp(return_to_normalize))
+ {
+ // Issue: external library crashed via signal
+ // If you encountered this, please try to figure out what's wrong:
+ // 1. Verify that library's input is 'sane'
+ // 2. Check if we have an NSexception to work with (unlikely)
+ // 3. See if passing same string causes exception to repeat
+ //
+ // Crash happens at uriNormalizeSyntaxExA
+ // Warning!!! This does not properly unwind stack,
+ // if this can be handled by NSexception, it needs to be remade
+ llassert(0);
+
+ LL_WARNS() << "Uriparser crashed with SIGILL, while processing: " << mNormalizedUri << LL_ENDL;
+ signal(SIGILL, last_handler);
+ return 1;
+ }
+#endif
+
+ mRes = uriNormalizeSyntaxExA(&mUri, URI_NORMALIZE_SCHEME | URI_NORMALIZE_HOST);
+
+#if LL_DARWIN
+ signal(SIGILL, last_handler);
+#endif
+
+ if (!mRes)
+ {
+ S32 chars_required;
+ mRes = uriToStringCharsRequiredA(&mUri, &chars_required);
+
+ if (!mRes)
+ {
+ chars_required++;
+ std::vector<char> label_buf(chars_required);
+ mRes = uriToStringA(&label_buf[0], &mUri, chars_required, NULL);
+
+ if (!mRes)
+ {
+ mNormalizedUri = &label_buf[mTmpScheme ? 7 : 0];
+ mTmpScheme = false;
+ }
+ }
+ }
}
if(mTmpScheme)