Skip to content

Commit 79034bd

Browse files
committed
fix(linker): prevent overflow when estimating CLI arg list length
This also updates the estimate on Windows of the length argument list to `saturating_add` to avoid overflow.
1 parent f7b4354 commit 79034bd

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

compiler/rustc_codegen_ssa/src/back/command.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,8 @@ impl Command {
166166
// [1]: https://docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-createprocessa
167167
// [2]: https://devblogs.microsoft.com/oldnewthing/?p=41553
168168

169-
let estimated_command_line_len = self.args.iter().map(|a| a.len()).sum::<usize>();
169+
let estimated_command_line_len =
170+
self.args.iter().fold(0usize, |acc, a| acc.saturating_add(a.as_encoded_bytes().len()));
170171
estimated_command_line_len > 1024 * 6
171172
}
172173
}

0 commit comments

Comments
 (0)