diff options
| author | Weihang Lo <me@weihanglo.tw> | 2025-03-12 20:58:56 -0400 |
|---|---|---|
| committer | Weihang Lo <me@weihanglo.tw> | 2025-03-14 09:42:12 -0400 |
| commit | 79034bd291c13b92d68561ba957dc898c6ad3ae7 (patch) | |
| tree | 9010905c3f82e077c6b05ecfcb0cbdda0235060c /compiler/rustc_codegen_ssa/src | |
| parent | f7b43542838f0a4a6cfdb17fbeadf45002042a77 (diff) | |
| download | rust-79034bd291c13b92d68561ba957dc898c6ad3ae7.tar.gz rust-79034bd291c13b92d68561ba957dc898c6ad3ae7.zip | |
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.
Diffstat (limited to 'compiler/rustc_codegen_ssa/src')
| -rw-r--r-- | compiler/rustc_codegen_ssa/src/back/command.rs | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/compiler/rustc_codegen_ssa/src/back/command.rs b/compiler/rustc_codegen_ssa/src/back/command.rs index 383d0579e52..84252386041 100644 --- a/compiler/rustc_codegen_ssa/src/back/command.rs +++ b/compiler/rustc_codegen_ssa/src/back/command.rs @@ -166,7 +166,8 @@ impl Command { // [1]: https://docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-createprocessa // [2]: https://devblogs.microsoft.com/oldnewthing/?p=41553 - let estimated_command_line_len = self.args.iter().map(|a| a.len()).sum::<usize>(); + let estimated_command_line_len = + self.args.iter().fold(0usize, |acc, a| acc.saturating_add(a.as_encoded_bytes().len())); estimated_command_line_len > 1024 * 6 } } |
