Skip to content

Commit 09911c1

Browse files
authored
Add option to enable SSP (#141)
* Add option to enable SSP * Don't include empty set twice * Respect the toolchain toml
1 parent dedbc6f commit 09911c1

File tree

6 files changed

+19
-7
lines changed

6 files changed

+19
-7
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Added
1111

12+
- Added option to enable Stack smashing protection (#141)
13+
1214
### Changed
1315

1416
### Fixed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ You can also directly download pre-compiled [release binaries] or use [`cargo-bi
4545
- `wifi`: Enables Wi-Fi via the `esp-wifi` crate; requires `alloc`.
4646
- `ble`: Enables BLE via the `esp-wifi` crate; requires `alloc`.
4747
- `embassy`: Adds `embassy` framework support.
48+
- `stack-smashing-protection`: Enables [stack smashing protection](https://doc.rust-lang.org/rustc/exploit-mitigations.html#stack-smashing-protection). Requires nightly Rust.
4849
- `probe-rs`: Replaces `espflash` with `probe-rs` and enables RTT-based options.
4950
- `flashing-probe-rs`: Contains options that require `probe-rs`:
5051
- `defmt`: Adds support for `defmt` printing. Uses `rtt-target` as the RTT implementation.

template/.cargo/config.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ rustflags = [
2727
# NOTE: May negatively impact performance of produced code
2828
"-C", "force-frame-pointers",
2929
#ENDIF
30+
#IF option("stack-smashing-protection")
31+
"-Z", "stack-protector=all",
32+
#ENDIF
3033
]
3134

3235
#REPLACE riscv32imac-unknown-none-elf rust_target

template/rust-toolchain.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
[toolchain]
22
#IF option("riscv")
3+
#IF option("stack-smashing-protection")
4+
#+channel = "nightly"
5+
#ELSE
36
channel = "stable"
7+
#ENDIF
48
components = ["rust-src"]
59
#REPLACE riscv32imac-unknown-none-elf rust_target
610
targets = ["riscv32imac-unknown-none-elf"]

template/template.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ options:
4848
requires:
4949
- unstable-hal
5050

51+
- !Option
52+
name: stack-smashing-protection
53+
display_name: Enable stack smashing protection.
54+
help: Requires nightly Rust.
55+
5156
- !Option
5257
name: probe-rs
5358
display_name: Use probe-rs to flash and monitor instead of espflash.

xtask/src/main.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,40 +105,38 @@ fn check(
105105
// Ensure that the generated project builds without errors:
106106
let output = Command::new("cargo")
107107
.args([if build { "build" } else { "check" }])
108+
.env_remove("RUSTUP_TOOLCHAIN")
108109
.current_dir(project_path.join(PROJECT_NAME))
109110
.stdout(Stdio::inherit())
110111
.stderr(Stdio::inherit())
111112
.output()?;
112113
if !output.status.success() {
113-
project_dir.close()?;
114114
bail!("Failed to execute cargo check subcommand")
115115
}
116116

117117
// Run clippy against the generated project to check for lint errors:
118118
let output = Command::new("cargo")
119119
.args(["clippy", "--no-deps", "--", "-Dwarnings"])
120+
.env_remove("RUSTUP_TOOLCHAIN")
120121
.current_dir(project_path.join(PROJECT_NAME))
121122
.stdout(Stdio::inherit())
122123
.stderr(Stdio::inherit())
123124
.output()?;
124125
if !output.status.success() {
125-
project_dir.close()?;
126126
bail!("Failed to execute cargo clippy subcommand")
127127
}
128128

129129
// Ensure that the generated project is correctly formatted:
130130
let output = Command::new("cargo")
131131
.args(["fmt", "--", "--check"])
132+
.env_remove("RUSTUP_TOOLCHAIN")
132133
.current_dir(project_path.join(PROJECT_NAME))
133134
.stdout(Stdio::inherit())
134135
.stderr(Stdio::inherit())
135136
.output()?;
136137
if !output.status.success() {
137-
project_dir.close()?;
138138
bail!("Failed to execute cargo fmt subcommand")
139139
}
140-
141-
project_dir.close()?;
142140
}
143141

144142
Ok(())
@@ -226,7 +224,7 @@ fn options_for_chip(chip: Chip, all_combinations: bool) -> Result<Vec<Vec<String
226224
}
227225

228226
// A list of each option, along with its dependencies
229-
let mut available_options = vec![];
227+
let mut available_options = vec![vec![]];
230228

231229
for option in all_options {
232230
let option = find_option(&option, &template.options).unwrap();
@@ -247,7 +245,6 @@ fn options_for_chip(chip: Chip, all_combinations: bool) -> Result<Vec<Vec<String
247245
available_options.dedup();
248246

249247
if !all_combinations {
250-
available_options.push(vec![]);
251248
return Ok(available_options);
252249
}
253250

0 commit comments

Comments
 (0)