about summary refs log tree commit diff
path: root/compiler/rustc_driver_impl/src/lib.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2023-05-27 20:27:23 +0000
committerbors <bors@rust-lang.org>2023-05-27 20:27:23 +0000
commitcca7ee58110726983951a19d5fb7316d9243925d (patch)
tree9700cd93278056f3beb0c5da9844fbe60a4c73ca /compiler/rustc_driver_impl/src/lib.rs
parentbc428f82f5cfbaeca46122efe4784c8e819be4ac (diff)
parent9f5dce7d757583967bcd0a9da7cc489968c4542f (diff)
downloadrust-cca7ee58110726983951a19d5fb7316d9243925d.tar.gz
rust-cca7ee58110726983951a19d5fb7316d9243925d.zip
Auto merge of #112025 - matthiaskrgr:rollup-j693v67, r=matthiaskrgr
Rollup of 6 pull requests

Successful merges:

 - #108630 (Fix docs for `alloc::realloc`)
 - #109084 (rustc driver: Remove argument 0 before at-expansion to prevent ICE)
 - #111181 (fix(parse): return unpected when current token is EOF)
 - #111656 (Use an unbounded lifetime in `String::leak`.)
 - #111946 (rustdoc: Add `ItemTemplate` trait and related functions to avoid repetitively wrapping existing functions)
 - #112018 (Clean up usage of `cx.tcx` when `tcx` is already set into a variable)

r? `@ghost`
`@rustbot` modify labels: rollup
Diffstat (limited to 'compiler/rustc_driver_impl/src/lib.rs')
-rw-r--r--compiler/rustc_driver_impl/src/lib.rs13
1 files changed, 10 insertions, 3 deletions
diff --git a/compiler/rustc_driver_impl/src/lib.rs b/compiler/rustc_driver_impl/src/lib.rs
index 40aa69e5a41..0b5d737091e 100644
--- a/compiler/rustc_driver_impl/src/lib.rs
+++ b/compiler/rustc_driver_impl/src/lib.rs
@@ -250,6 +250,16 @@ fn run_compiler(
         Box<dyn FnOnce(&config::Options) -> Box<dyn CodegenBackend> + Send>,
     >,
 ) -> interface::Result<()> {
+    // Throw away the first argument, the name of the binary.
+    // In case of at_args being empty, as might be the case by
+    // passing empty argument array to execve under some platforms,
+    // just use an empty slice.
+    //
+    // This situation was possible before due to arg_expand_all being
+    // called before removing the argument, enabling a crash by calling
+    // the compiler with @empty_file as argv[0] and no more arguments.
+    let at_args = at_args.get(1..).unwrap_or_default();
+
     let args = args::arg_expand_all(at_args);
 
     let Some(matches) = handle_options(&args) else { return Ok(()) };
@@ -1074,9 +1084,6 @@ fn print_flag_list<T>(
 /// So with all that in mind, the comments below have some more detail about the
 /// contortions done here to get things to work out correctly.
 pub fn handle_options(args: &[String]) -> Option<getopts::Matches> {
-    // Throw away the first argument, the name of the binary
-    let args = &args[1..];
-
     if args.is_empty() {
         // user did not write `-v` nor `-Z unstable-options`, so do not
         // include that extra information.