diff options
author | Mark Wielaard <mark@klomp.org> | 2021-09-29 22:03:34 +0200 |
---|---|---|
committer | Mark Wielaard <mark@klomp.org> | 2021-09-29 22:03:34 +0200 |
commit | e6e1cc117e1f08dfde86f5a3b1988e4b7206a7da (patch) | |
tree | 9e968a66f2c66220cc220a471861c416f162dc40 /gcc | |
parent | 28f527c9598339cf834a30b5ee1f14258b8ecbb2 (diff) | |
download | gcc-e6e1cc117e1f08dfde86f5a3b1988e4b7206a7da.zip gcc-e6e1cc117e1f08dfde86f5a3b1988e4b7206a7da.tar.gz gcc-e6e1cc117e1f08dfde86f5a3b1988e4b7206a7da.tar.bz2 |
Fix raw byte string parsing of zero and out of range bytes
Allow \0 escape in raw byte string and reject non-ascii byte
values. Change parse_partial_hex_escapes to not skip bad characters to
provide better error messages.
Add rawbytestring.rs testcase to check string, raw string, byte string
and raw byte string parsing.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/rust/lex/rust-lex.cc | 20 | ||||
-rw-r--r-- | gcc/testsuite/rust/compile/rawbytestring.rs | bin | 0 -> 3234 bytes |
2 files changed, 15 insertions, 5 deletions
diff --git a/gcc/rust/lex/rust-lex.cc b/gcc/rust/lex/rust-lex.cc index b70877b..bbddea0 100644 --- a/gcc/rust/lex/rust-lex.cc +++ b/gcc/rust/lex/rust-lex.cc @@ -1423,8 +1423,7 @@ Lexer::parse_partial_hex_escape () char hexNum[3] = {0, 0, 0}; // first hex char - skip_input (); - current_char = peek_input (); + current_char = peek_input (1); int additional_length_offset = 1; if (!is_x_digit (current_char)) @@ -1432,20 +1431,23 @@ Lexer::parse_partial_hex_escape () rust_error_at (get_current_location (), "invalid character %<\\x%c%> in \\x sequence", current_char); + return std::make_pair (0, 0); } hexNum[0] = current_char; // second hex char skip_input (); - current_char = peek_input (); + current_char = peek_input (1); additional_length_offset++; if (!is_x_digit (current_char)) { rust_error_at (get_current_location (), - "invalid character %<\\x%c%> in \\x sequence", + "invalid character %<\\x%c%c%> in \\x sequence", hexNum[0], current_char); + return std::make_pair (0, 1); } + skip_input (); hexNum[1] = current_char; long hexLong = std::strtol (hexNum, nullptr, 16); @@ -1627,7 +1629,7 @@ Lexer::parse_byte_string (Location loc) else length += std::get<1> (escape_length_pair); - if (output_char != 0) + if (output_char != 0 || !std::get<2> (escape_length_pair)) str += output_char; continue; @@ -1722,6 +1724,14 @@ Lexer::parse_raw_byte_string (Location loc) } } + if ((unsigned char) current_char > 127) + { + rust_error_at (get_current_location (), + "character %<%c%> in raw byte string out of range", + current_char); + current_char = 0; + } + length++; str += current_char; diff --git a/gcc/testsuite/rust/compile/rawbytestring.rs b/gcc/testsuite/rust/compile/rawbytestring.rs Binary files differnew file mode 100644 index 0000000..9c6b762 --- /dev/null +++ b/gcc/testsuite/rust/compile/rawbytestring.rs |