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

[beta] Don't treat unnormalized function arguments as well-formed #91242

Closed
wants to merge 58 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
aa3c2ae
switch release channel to beta
pietroalbini Oct 18, 2021
d464727
Auto merge of #90005 - pietroalbini:beta-next, r=pietroalbini
bors Oct 18, 2021
59f11bb
Don't emit a warning for empty rmeta files.
ehuss Oct 19, 2021
13704da
Erase late-bound regions before computing vtable debuginfo name.
michaelwoerister Oct 19, 2021
06221e1
Update src/test/codegen/debug-vtable.rs
wesleywiser Oct 19, 2021
b68ede6
Fix issue 90038
nbdd0121 Oct 19, 2021
e89b532
Revert "Rollup merge of #86011 - tlyu:correct-sized-bound-spans, r=es…
JohnTitor Oct 18, 2021
012c77b
Add a regression test for #89935
JohnTitor Oct 18, 2021
5e20539
Deduplicate macro_rules! from module_exports when documenting them
Urgau Oct 13, 2021
1ed389d
Add regression test for #89852
Urgau Oct 14, 2021
d46c106
Oops, inverted condition, fix that
Urgau Oct 14, 2021
d0dfc22
Apply documentation suggestions from code review
Urgau Oct 15, 2021
caa27dd
Add equivalent test in src/test/rustdoc
Urgau Oct 15, 2021
245acae
Rework the equivalent test to work with sidebar-items.js
Urgau Oct 15, 2021
88e4e0e
Bump cargo
Mark-Simulacrum Oct 22, 2021
7e4c9ee
Auto merge of #90151 - Mark-Simulacrum:beta-next, r=Mark-Simulacrum
bors Oct 22, 2021
20c6049
Lint against RTL unicode codepoints in literals and comments
estebank Aug 19, 2021
a59d96e
add 1.56.1 to the release notes
pietroalbini Oct 31, 2021
708d57e
Auto merge of #90461 - pietroalbini:bidi-beta, r=nikomatsakis
bors Nov 1, 2021
e1225bf
Auto merge of #7810 - camsteffen:if-then-panic-pedantic, r=flip1995
bors Oct 28, 2021
d23a338
Format backport to pass CI
flip1995 Nov 3, 2021
00e31fa
Auto merge of #7925 - flip1995:backport, r=flip1995
bors Nov 3, 2021
4cd7ad0
Merge commit '00e31fa5af1895bf8ff1e2b1e25b041362cdc33e' into clippy_b…
flip1995 Nov 4, 2021
f7acd9f
Fix assertion failures in `OwnedHandle` with `windows_subsystem`.
sunfishcode Sep 9, 2021
2df9cc5
Fix Windows compilation errors.
sunfishcode Sep 9, 2021
0693aa1
Document the valid values for `HandleOrNull` and `HandleOrInvalid`.
sunfishcode Oct 5, 2021
9654d52
Ensure that pushing empty path works as before
seanyoung Oct 8, 2021
427b6a7
Feature gate and make must_not_suspend allow-by-default
guswynn Oct 12, 2021
4b4b56d
Only use `clone3` when needed for pidfd
cuviper Oct 15, 2021
aaa8f4e
Update another comment on fork vs. clone3
cuviper Oct 15, 2021
462002b
Also note tool expectations of fork vs clone3
cuviper Oct 15, 2021
d658d6d
Revert "Do not call getpid wrapper after fork in tests"
cuviper Oct 15, 2021
d19aeb2
Fix documentation header sizes
jsha Oct 22, 2021
3374d0d
Fixes incorrect handling of ADT's drop requirements
JakobDegen Oct 23, 2021
4f9474c
Add regresstion test for #90024.
JakobDegen Oct 24, 2021
d092236
Clean up debug statements in needs_drop
JakobDegen Oct 26, 2021
2039a92
Fix ICE when forgetting to `Box` a parameter to a `Self::func` call
JakobDegen Oct 24, 2021
7a83694
expose default substs in param_env
b-naber Oct 25, 2021
96fd370
add tests
b-naber Oct 25, 2021
dc73bdc
Update odht crate to 0.3.1 (big-endian bugfix)
michaelwoerister Oct 29, 2021
640bfaf
Add more missing methods to `IntraLinkCrateLoader`
jyn514 Nov 8, 2021
5fd4bb4
Go back to loading all external crates unconditionally
jyn514 Nov 1, 2021
082accd
Split doc_cfg and doc_auto_cfg features
GuillaumeGomez Nov 2, 2021
fb40f17
Also check for feature gates in "src/test/rustdoc"
GuillaumeGomez Nov 2, 2021
fed62b2
Apply adjustments for field expression even if inaccessible
nbdd0121 Nov 2, 2021
5de0c84
introduce an enum for tracking the 2229 migration causes
nikomatsakis Nov 4, 2021
042c837
rework diagnostic reporting to be more structured
nikomatsakis Nov 4, 2021
34cd4ef
handle case of a variable not captured
nikomatsakis Nov 5, 2021
d9ddee4
apply suggestions from code review
nikomatsakis Nov 5, 2021
e63c3b5
Properly register text_direction_codepoint_in_comment lint.
hkratz Nov 5, 2021
cba2546
Bump stage0 to stable 1.56.1
cuviper Nov 16, 2021
236bc61
Use ubuntu image to download openssl, curl sources, cacert.pem
hkratz Oct 31, 2021
69b4a85
Ignore files copied from previous stage when generating hash.
hkratz Nov 1, 2021
4d156c3
Android is not GNU
cuviper Nov 12, 2021
a4a72e7
Update llvm submodule
Amanieu Nov 16, 2021
7611e64
Auto merge of #90938 - cuviper:beta-next, r=Mark-Simulacrum
bors Nov 19, 2021
ef1a3b9
Auto merge of #90561 - flip1995:clippy_backport, r=Mark-Simulacrum
bors Nov 19, 2021
da0dc91
Don't treat unnormalized function arguments as well-formed
jackh726 Nov 26, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2315,9 +2315,9 @@ dependencies = [

[[package]]
name = "odht"
version = "0.3.0"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d2504d29fda40b3f2f9ef525392435ab660e407c188196cb664b116ebcca0142"
checksum = "5a518809ac14b25b569624d0268eba1e88498f71615893dca57982bed7621abb"
dependencies = [
"cfg-if 1.0.0",
]
Expand Down Expand Up @@ -4223,6 +4223,7 @@ dependencies = [
"rustc_span",
"tracing",
"unicode-normalization",
"unicode-width",
]

[[package]]
Expand Down
8 changes: 8 additions & 0 deletions RELEASES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
Version 1.56.1 (2021-11-01)
===========================

- New lints to detect the presence of bidirectional-override Unicode
codepoints in the compiled source code ([CVE-2021-42574])

[CVE-2021-42574]: https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2021-42574

Version 1.56.0 (2021-10-21)
========================

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,6 @@ impl UniversalRegionRelationsBuilder<'cx, 'tcx> {
debug!("build: input_or_output={:?}", ty);
// We add implied bounds from both the unnormalized and normalized ty
// See issue #87748
let constraints_implied_1 = self.add_implied_bounds(ty);
let TypeOpOutput { output: norm_ty, constraints: constraints1, .. } = self
.param_env
.and(type_op::normalize::Normalize::new(ty))
Expand Down Expand Up @@ -286,10 +285,9 @@ impl UniversalRegionRelationsBuilder<'cx, 'tcx> {
// }
// ```
// Both &Self::Bar and &() are WF
let constraints_implied_2 =
if ty != norm_ty { self.add_implied_bounds(norm_ty) } else { None };
let constraints_implied = self.add_implied_bounds(norm_ty);
normalized_inputs_and_output.push(norm_ty);
constraints1.into_iter().chain(constraints_implied_1).chain(constraints_implied_2)
constraints1.into_iter().chain(constraints_implied)
})
.collect();

Expand Down
11 changes: 4 additions & 7 deletions compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs
Original file line number Diff line number Diff line change
Expand Up @@ -480,14 +480,11 @@ pub fn compute_debuginfo_vtable_name<'tcx>(
}

if let Some(trait_ref) = trait_ref {
push_item_name(tcx, trait_ref.skip_binder().def_id, true, &mut vtable_name);
let trait_ref =
tcx.normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), trait_ref);
push_item_name(tcx, trait_ref.def_id, true, &mut vtable_name);
visited.clear();
push_generic_params_internal(
tcx,
trait_ref.skip_binder().substs,
&mut vtable_name,
&mut visited,
);
push_generic_params_internal(tcx, trait_ref.substs, &mut vtable_name, &mut visited);
} else {
vtable_name.push_str("_");
}
Expand Down
20 changes: 19 additions & 1 deletion compiler/rustc_errors/src/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2054,8 +2054,26 @@ fn num_decimal_digits(num: usize) -> usize {
MAX_DIGITS
}

// We replace some characters so the CLI output is always consistent and underlines aligned.
const OUTPUT_REPLACEMENTS: &[(char, &str)] = &[
('\t', " "), // We do our own tab replacement
('\u{202A}', ""), // The following unicode text flow control characters are inconsistently
('\u{202B}', ""), // supported accross CLIs and can cause confusion due to the bytes on disk
('\u{202D}', ""), // not corresponding to the visible source code, so we replace them always.
('\u{202E}', ""),
('\u{2066}', ""),
('\u{2067}', ""),
('\u{2068}', ""),
('\u{202C}', ""),
('\u{2069}', ""),
];

fn replace_tabs(str: &str) -> String {
str.replace('\t', " ")
let mut s = str.to_string();
for (c, replacement) in OUTPUT_REPLACEMENTS {
s = s.replace(*c, replacement);
}
s
}

fn draw_col_separator(buffer: &mut StyledBuffer, line: usize, col: usize) {
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_feature/src/active.rs
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,9 @@ declare_features! (
/// Allows using the `non_exhaustive_omitted_patterns` lint.
(active, non_exhaustive_omitted_patterns_lint, "1.57.0", Some(89554), None),

/// Tells rustdoc to automatically generate `#[doc(cfg(...))]`.
(active, doc_auto_cfg, "1.57.0", Some(43781), None),

// -------------------------------------------------------------------------
// feature-group-end: actual feature gates
// -------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ rustc_serialize = { path = "../rustc_serialize" }
rustc_ast = { path = "../rustc_ast" }
tracing = "0.1"
smallvec = { version = "1.6.1", features = ["union", "may_dangle"] }
odht = { version = "0.3.0", features = ["nightly"] }
odht = { version = "0.3.1", features = ["nightly"] }
39 changes: 38 additions & 1 deletion compiler/rustc_lint/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

use self::TargetLint::*;

use crate::hidden_unicode_codepoints::UNICODE_TEXT_FLOW_CHARS;
use crate::levels::{is_known_lint_tool, LintLevelsBuilder};
use crate::passes::{EarlyLintPassObject, LateLintPassObject};
use rustc_ast as ast;
Expand All @@ -39,7 +40,7 @@ use rustc_session::lint::{BuiltinLintDiagnostics, ExternDepSpec};
use rustc_session::lint::{FutureIncompatibleInfo, Level, Lint, LintBuffer, LintId};
use rustc_session::Session;
use rustc_span::lev_distance::find_best_match_for_name;
use rustc_span::{symbol::Symbol, MultiSpan, Span, DUMMY_SP};
use rustc_span::{symbol::Symbol, BytePos, MultiSpan, Span, DUMMY_SP};
use rustc_target::abi;
use tracing::debug;

Expand Down Expand Up @@ -597,6 +598,42 @@ pub trait LintContext: Sized {
// Now, set up surrounding context.
let sess = self.sess();
match diagnostic {
BuiltinLintDiagnostics::UnicodeTextFlow(span, content) => {
let spans: Vec<_> = content
.char_indices()
.filter_map(|(i, c)| {
UNICODE_TEXT_FLOW_CHARS.contains(&c).then(|| {
let lo = span.lo() + BytePos(2 + i as u32);
(c, span.with_lo(lo).with_hi(lo + BytePos(c.len_utf8() as u32)))
})
})
.collect();
let (an, s) = match spans.len() {
1 => ("an ", ""),
_ => ("", "s"),
};
db.span_label(span, &format!(
"this comment contains {}invisible unicode text flow control codepoint{}",
an,
s,
));
for (c, span) in &spans {
db.span_label(*span, format!("{:?}", c));
}
db.note(
"these kind of unicode codepoints change the way text flows on \
applications that support them, but can cause confusion because they \
change the order of characters on the screen",
);
if !spans.is_empty() {
db.multipart_suggestion_with_style(
"if their presence wasn't intentional, you can remove them",
spans.into_iter().map(|(_, span)| (span, "".to_string())).collect(),
Applicability::MachineApplicable,
SuggestionStyle::HideCodeAlways,
);
}
},
BuiltinLintDiagnostics::Normal => (),
BuiltinLintDiagnostics::BareTraitObject(span, is_global) => {
let (sugg, app) = match sess.source_map().span_to_snippet(span) {
Expand Down
161 changes: 161 additions & 0 deletions compiler/rustc_lint/src/hidden_unicode_codepoints.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
use crate::{EarlyContext, EarlyLintPass, LintContext};
use rustc_ast as ast;
use rustc_errors::{Applicability, SuggestionStyle};
use rustc_span::{BytePos, Span, Symbol};

declare_lint! {
/// The `text_direction_codepoint_in_literal` lint detects Unicode codepoints that change the
/// visual representation of text on screen in a way that does not correspond to their on
/// memory representation.
///
/// ### Explanation
///
/// The unicode characters `\u{202A}`, `\u{202B}`, `\u{202D}`, `\u{202E}`, `\u{2066}`,
/// `\u{2067}`, `\u{2068}`, `\u{202C}` and `\u{2069}` make the flow of text on screen change
/// its direction on software that supports these codepoints. This makes the text "abc" display
/// as "cba" on screen. By leveraging software that supports these, people can write specially
/// crafted literals that make the surrounding code seem like it's performing one action, when
/// in reality it is performing another. Because of this, we proactively lint against their
/// presence to avoid surprises.
///
/// ### Example
///
/// ```rust,compile_fail
/// #![deny(text_direction_codepoint_in_literal)]
/// fn main() {
/// println!("{:?}", '‮');
/// }
/// ```
///
/// {{produces}}
///
pub TEXT_DIRECTION_CODEPOINT_IN_LITERAL,
Deny,
"detect special Unicode codepoints that affect the visual representation of text on screen, \
changing the direction in which text flows",
}

declare_lint_pass!(HiddenUnicodeCodepoints => [TEXT_DIRECTION_CODEPOINT_IN_LITERAL]);

crate const UNICODE_TEXT_FLOW_CHARS: &[char] = &[
'\u{202A}', '\u{202B}', '\u{202D}', '\u{202E}', '\u{2066}', '\u{2067}', '\u{2068}', '\u{202C}',
'\u{2069}',
];

impl HiddenUnicodeCodepoints {
fn lint_text_direction_codepoint(
&self,
cx: &EarlyContext<'_>,
text: Symbol,
span: Span,
padding: u32,
point_at_inner_spans: bool,
label: &str,
) {
// Obtain the `Span`s for each of the forbidden chars.
let spans: Vec<_> = text
.as_str()
.char_indices()
.filter_map(|(i, c)| {
UNICODE_TEXT_FLOW_CHARS.contains(&c).then(|| {
let lo = span.lo() + BytePos(i as u32 + padding);
(c, span.with_lo(lo).with_hi(lo + BytePos(c.len_utf8() as u32)))
})
})
.collect();

cx.struct_span_lint(TEXT_DIRECTION_CODEPOINT_IN_LITERAL, span, |lint| {
let mut err = lint.build(&format!(
"unicode codepoint changing visible direction of text present in {}",
label
));
let (an, s) = match spans.len() {
1 => ("an ", ""),
_ => ("", "s"),
};
err.span_label(
span,
&format!(
"this {} contains {}invisible unicode text flow control codepoint{}",
label, an, s,
),
);
if point_at_inner_spans {
for (c, span) in &spans {
err.span_label(*span, format!("{:?}", c));
}
}
err.note(
"these kind of unicode codepoints change the way text flows on applications that \
support them, but can cause confusion because they change the order of \
characters on the screen",
);
if point_at_inner_spans && !spans.is_empty() {
err.multipart_suggestion_with_style(
"if their presence wasn't intentional, you can remove them",
spans.iter().map(|(_, span)| (*span, "".to_string())).collect(),
Applicability::MachineApplicable,
SuggestionStyle::HideCodeAlways,
);
err.multipart_suggestion(
"if you want to keep them but make them visible in your source code, you can \
escape them",
spans
.into_iter()
.map(|(c, span)| {
let c = format!("{:?}", c);
(span, c[1..c.len() - 1].to_string())
})
.collect(),
Applicability::MachineApplicable,
);
} else {
// FIXME: in other suggestions we've reversed the inner spans of doc comments. We
// should do the same here to provide the same good suggestions as we do for
// literals above.
err.note("if their presence wasn't intentional, you can remove them");
err.note(&format!(
"if you want to keep them but make them visible in your source code, you can \
escape them: {}",
spans
.into_iter()
.map(|(c, _)| { format!("{:?}", c) })
.collect::<Vec<String>>()
.join(", "),
));
}
err.emit();
});
}
}
impl EarlyLintPass for HiddenUnicodeCodepoints {
fn check_attribute(&mut self, cx: &EarlyContext<'_>, attr: &ast::Attribute) {
if let ast::AttrKind::DocComment(_, comment) = attr.kind {
if comment.as_str().contains(UNICODE_TEXT_FLOW_CHARS) {
self.lint_text_direction_codepoint(cx, comment, attr.span, 0, false, "doc comment");
}
}
}

fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &ast::Expr) {
// byte strings are already handled well enough by `EscapeError::NonAsciiCharInByteString`
let (text, span, padding) = match &expr.kind {
ast::ExprKind::Lit(ast::Lit { token, kind, span }) => {
let text = token.symbol;
if !text.as_str().contains(UNICODE_TEXT_FLOW_CHARS) {
return;
}
let padding = match kind {
// account for `"` or `'`
ast::LitKind::Str(_, ast::StrStyle::Cooked) | ast::LitKind::Char(_) => 1,
// account for `r###"`
ast::LitKind::Str(_, ast::StrStyle::Raw(val)) => *val as u32 + 2,
_ => return,
};
(text, span, padding)
}
_ => return,
};
self.lint_text_direction_codepoint(cx, text, *span, padding, true, "literal");
}
}
4 changes: 3 additions & 1 deletion compiler/rustc_lint/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ pub mod builtin;
mod context;
mod early;
mod enum_intrinsics_non_enums;
pub mod hidden_unicode_codepoints;
mod internal;
mod late;
mod levels;
Expand Down Expand Up @@ -78,6 +79,7 @@ use rustc_span::Span;
use array_into_iter::ArrayIntoIter;
use builtin::*;
use enum_intrinsics_non_enums::EnumIntrinsicsNonEnums;
use hidden_unicode_codepoints::*;
use internal::*;
use methods::*;
use non_ascii_idents::*;
Expand Down Expand Up @@ -129,6 +131,7 @@ macro_rules! early_lint_passes {
DeprecatedAttr: DeprecatedAttr::new(),
WhileTrue: WhileTrue,
NonAsciiIdents: NonAsciiIdents,
HiddenUnicodeCodepoints: HiddenUnicodeCodepoints,
IncompleteFeatures: IncompleteFeatures,
RedundantSemicolons: RedundantSemicolons,
UnusedDocComment: UnusedDocComment,
Expand Down Expand Up @@ -300,7 +303,6 @@ fn register_builtins(store: &mut LintStore, no_interleave_lints: bool) {
UNUSED_LABELS,
UNUSED_PARENS,
UNUSED_BRACES,
MUST_NOT_SUSPEND,
REDUNDANT_SEMICOLONS
);

Expand Down
Loading