fix(cli): prevent linker argument overflow on Windows (#4126)
This commit is contained in:
1 parent
bd3b2da7a4
commit
78e65f240c
1 file changed
+8
-6
@@ -122,7 +122,7 @@ impl LinkAction {
|
|||||||
/// The file will be given by the dx-magic-link-arg env var itself, so we use
|
/// The file will be given by the dx-magic-link-arg env var itself, so we use
|
||||||
/// it both for determining if we should act as a linker and the for the file name itself.
|
/// it both for determining if we should act as a linker and the for the file name itself.
|
||||||
async fn run_link_inner(self) -> Result<()> {
|
async fn run_link_inner(self) -> Result<()> {
|
||||||
let mut args: Vec<_> = std::env::args().collect();
|
let mut args: Vec<_> = std::env::args().skip(1).collect();
|
||||||
if args.is_empty() {
|
if args.is_empty() {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
@@ -131,16 +131,18 @@ impl LinkAction {
|
|||||||
|
|
||||||
// Write the linker args to a file for the main process to read
|
// Write the linker args to a file for the main process to read
|
||||||
// todo: we might need to encode these as escaped shell words in case newlines are passed
|
// todo: we might need to encode these as escaped shell words in case newlines are passed
|
||||||
std::fs::write(self.link_args_file, args.join("\n"))?;
|
std::fs::write(&self.link_args_file, args.join("\n"))?;
|
||||||
|
|
||||||
// If there's a linker specified, we use that. Otherwise, we write a dummy object file to satisfy
|
// If there's a linker specified, we use that. Otherwise, we write a dummy object file to satisfy
|
||||||
// any post-processing steps that rustc does.
|
// any post-processing steps that rustc does.
|
||||||
match self.linker {
|
match self.linker {
|
||||||
Some(linker) => {
|
Some(linker) => {
|
||||||
let res = std::process::Command::new(linker)
|
let mut cmd = std::process::Command::new(linker);
|
||||||
.args(args.iter().skip(1))
|
match cfg!(target_os = "windows") {
|
||||||
.output()
|
true => cmd.arg(format!("@{}", &self.link_args_file.display())),
|
||||||
.expect("Failed to run linker");
|
false => cmd.args(args),
|
||||||
|
};
|
||||||
|
let res = cmd.output().expect("Failed to run linker");
|
||||||
|
|
||||||
if !res.stderr.is_empty() || !res.stdout.is_empty() {
|
if !res.stderr.is_empty() || !res.stdout.is_empty() {
|
||||||
_ = std::fs::create_dir_all(self.link_err_file.parent().unwrap());
|
_ = std::fs::create_dir_all(self.link_err_file.parent().unwrap());
|
||||||
|
|||||||
Reference in new issue
Block a user