Skip to content

[Parse] Disable support for multiline/extended escaping string literal in attribute message #19206

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

Merged
merged 1 commit into from
Sep 10, 2018

Conversation

rintaro
Copy link
Member

@rintaro rintaro commented Sep 8, 2018

Strings of diagnostics message processed in EncodedDiagnosticMessage aren't necessarily from parsed Swift source code. That means, they might not have quotes around it. Furthermore, memory around them might not be managed. The logic in Lexer::getEncodedStringSegment() used to cause
access violation
.

For now, disable multiline string literal and extended escaping in string literal for attribute message position. Considering the message might be from Clang, we cannot simply enable this.

rdar://problem/44228891

in attribute message

Strings of diagnostics message processed in EncodedDiagnosticMessage
aren't necessarily from parsed Swift source code. That means, they might
not have quotes around it. Furthermore, memory around them might not be
managed. The logic in 'Lexer::getEncodedStringSegment()' used to cause
access violation.

For now, disable multiline string literal and extended escaping in string
literal for attribute message position. Considering the message might be
from Clang, we cannot simply enable this.

rdar://problem/44228891
@rintaro
Copy link
Member Author

rintaro commented Sep 8, 2018

@swift-ci Please ASAN test

@rintaro
Copy link
Member Author

rintaro commented Sep 8, 2018

@swift-ci Please smoke test

@johnno1962
Copy link
Contributor

johnno1962 commented Sep 9, 2018

Hi @rintaro, fair enough, reading off the end of the buffer was not clever here. I’m not too fussed about raw strings in depreciation messages but multiline strings could be useful to provide more detailed info.

How about the following in Lexer::getEncodedStringSegment():

  // Special case when being called from EncodedDiagnosticMessage(...)
  // This allows multiline strings to work as attribute messages.
  if (IndentToStrip == ~0u) {
    const char *Trailing = Bytes.end() - 1;
    while (Trailing > BytesPtr && (*Trailing == ' ' || *Trailing == '\t'))
      Trailing--;

    IndentToStrip = Trailing >= BytesPtr && *Trailing == '\n' ?
      Bytes.end() - Trailing - 1 : 0;
  }

@rintaro
Copy link
Member Author

rintaro commented Sep 10, 2018

@johnno1962 Sounds good. Please post a new PR with test cases after I merge this change.

@benlangmuir
Copy link
Contributor

@swift-ci please smoke test macOS

@rintaro rintaro merged commit 66df646 into swiftlang:master Sep 10, 2018
@rintaro rintaro deleted the rdar44228891 branch September 10, 2018 17:01
@johnno1962
Copy link
Contributor

Followed up with #19219 which gets multiline messages working while respecting the bounds of the StringRef passed in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants