Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Thread Safety Warning in XHR String #185

Closed
tmbrbr opened this issue Jan 11, 2024 · 3 comments
Closed

Thread Safety Warning in XHR String #185

tmbrbr opened this issue Jan 11, 2024 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@tmbrbr
Copy link
Contributor

tmbrbr commented Jan 11, 2024

There is a compiler warning about thread safety in the XHR String implementation.

01:18:37  41:24.10 In file included from Unified_cpp_dom_xhr0.cpp:29:
01:18:37  41:24.11 /home/jenkins/agent/workspace/foxhound/dom/xhr/XMLHttpRequestString.cpp:50:5: warning: reading variable 'mData' requires holding mutex 'mMutex' [-Wthread-safety-analysis]
01:18:37  41:24.11    50 |     mData.Taint().concat(aTaint, aIndex);
01:18:37  41:24.11       |     ^
@tmbrbr tmbrbr added the bug Something isn't working label Jan 11, 2024
@leeN
Copy link
Collaborator

leeN commented Feb 1, 2024

Both the mentioned, as well as a warning in the HTMLParser, seem to rely on external locks.

  • Warning: dom/xhr/XMLHttpRequestString.cpp:50:5 [-Wthread-safety-analysis] reading variable 'mData' requires holding mutex 'mMutex'
  • Warning: parser/html/nsHtml5StreamParser.cpp:1734:11 [-Wthread-safety-analysis] calling function 'DoDataAvailable' requires holding mutex 'parser->mTokenizerMutex' exclusively

For the first warning, it is directly stated in a comment; for the second, the comment refers to the function the taint-aware version was copied from.

// Called under lock by function ptr
/* static */
nsresult nsHtml5StreamParser::CopySegmentsToParserNoTaint(
    nsIInputStream* aInStream, void* aClosure, const char* aFromSegment,
    uint32_t aToOffset, uint32_t aCount,
    uint32_t* aWriteCount) MOZ_NO_THREAD_SAFETY_ANALYSIS {
  nsHtml5StreamParser* parser = static_cast<nsHtml5StreamParser*>(aClosure);

  parser->DoDataAvailable(AsBytes(Span(aFromSegment, aCount)), EmptyTaint);
  // Assume DoDataAvailable consumed all available bytes.
  *aWriteCount = aCount;
  return NS_OK;
}

This is the original, and the following is warned about:

/* static */ nsresult
nsHtml5StreamParser::CopySegmentsToParser(
  nsITaintawareInputStream *aInStream, void *aClosure, const char *aFromSegment,
  uint32_t aToOffset, uint32_t aCount, const StringTaint& aTaint, uint32_t *aWriteCount) {
  nsHtml5StreamParser* parser = static_cast<nsHtml5StreamParser*>(aClosure);

  parser->DoDataAvailable(AsBytes(Span(aFromSegment, aCount)), aTaint); // <- warning here
  // Assume DoDataAvailable consumed all available bytes.
  *aWriteCount = aCount;
  return NS_OK;
}

So, I'd conclude it is sufficient to add the MOZ_NO_THREAD_SAFETY_ANALYSIS attribute to both functions. I'll open a PR.

@tmbrbr
Copy link
Contributor Author

tmbrbr commented Feb 1, 2024

Thanks for looking into this!

@tmbrbr
Copy link
Contributor Author

tmbrbr commented Feb 1, 2024

Closed by #197

@tmbrbr tmbrbr closed this as completed Feb 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants