Check for invalid ASCII in the scanner

This commit is contained in:
Alex Beregszaszi 2020-07-15 15:06:43 +01:00
parent da189a6678
commit 8abc1a6863
3 changed files with 11 additions and 0 deletions

View File

@ -7,6 +7,7 @@ Breaking changes:
* JSON AST: Remove members with ``null`` value from JSON output.
* Parser: Disallow ``gwei`` as identifier.
* Parser: Disallow dot syntax for ``value`` and ``gas``.
* Parser: Disallow non-printable characters in string literals.
* Parser: NatSpec comments on variables are only allowed for public state variables.
* Parser: Remove the ``finney`` and ``szabo`` denominations.
* Parser: Remove the identifier ``now`` (replaced by ``block.timestamp``).

View File

@ -73,6 +73,7 @@ string to_string(ScannerError _errorCode)
case ScannerError::IllegalHexDigit: return "Hexadecimal digit missing or invalid.";
case ScannerError::IllegalCommentTerminator: return "Expected multi-line comment-terminator.";
case ScannerError::IllegalEscapeSequence: return "Invalid escape sequence.";
case ScannerError::IllegalCharacterInString: return "Invalid character in string.";
case ScannerError::IllegalStringEndQuote: return "Expected string end-quote.";
case ScannerError::IllegalNumberSeparator: return "Invalid use of number separator '_'.";
case ScannerError::IllegalExponent: return "Invalid exponent.";
@ -789,8 +790,16 @@ Token Scanner::scanString()
return setError(ScannerError::IllegalEscapeSequence);
}
else
{
// Report error on non-printable characters in string literals.
//
// We are using a manual range and not isprint() to avoid
// any potential complications with locale.
if (static_cast<unsigned>(c) <= 0x1f || static_cast<unsigned>(c) >= 0x7f)
return setError(ScannerError::IllegalCharacterInString);
addLiteralChar(c);
}
}
if (m_char != quote)
return setError(ScannerError::IllegalStringEndQuote);
literal.complete();

View File

@ -77,6 +77,7 @@ enum class ScannerError
IllegalHexDigit,
IllegalCommentTerminator,
IllegalEscapeSequence,
IllegalCharacterInString,
IllegalStringEndQuote,
IllegalNumberSeparator,
IllegalExponent,