From 74c1a1438aa31243c757486947842c1e322ce581 Mon Sep 17 00:00:00 2001 From: egibs <20933572+egibs@users.noreply.github.com> Date: Sun, 9 Jun 2024 11:47:21 -0500 Subject: [PATCH 1/3] Add clippy Workflow Signed-off-by: egibs <20933572+egibs@users.noreply.github.com> --- .github/workflows/ci.yml | 3 +- .github/workflows/rust-clippy.yml | 50 +++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/rust-clippy.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a7a75e9..b27cd49 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,6 +8,7 @@ on: env: CARGO_TERM_COLOR: always + RUST_VERSION: 1.78.0 permissions: contents: read @@ -30,7 +31,7 @@ jobs: static.rust-lang.org:443 - uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 - run: | - curl https://sh.rustup.rs -sSf | sh -s -- -y + curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain=${{ env.RUST_VERSION }} -y export PATH="$HOME/.cargo/bin:$PATH" rustup default stable rustup component add rustfmt diff --git a/.github/workflows/rust-clippy.yml b/.github/workflows/rust-clippy.yml new file mode 100644 index 0000000..8189a86 --- /dev/null +++ b/.github/workflows/rust-clippy.yml @@ -0,0 +1,50 @@ +name: rust-clippy + +on: + push: + branches: + - main + pull_request: + branches: + - main + schedule: + - cron: '40 12 * * 6' + +env: + RUST_VERSION: 1.78.0 + +jobs: + rust-clippy: + name: Run rust-clippy + runs-on: ubuntu-latest + permissions: + contents: read + security-events: write + actions: read + steps: + - uses: step-security/harden-runner@17d0e2bd7d51742c71671bd19fa12bdc9d40a3d6 + with: + egress-policy: audit + - uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 + - name: Install Rust toolchain + run: | + curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain=${{ env.RUST_VERSION }} -y + export PATH="$HOME/.cargo/bin:$PATH" + rustup default stable + rustup component add clippy + + - name: Install required cargo + run: cargo install clippy-sarif sarif-fmt + + - name: Run rust-clippy + run: + cargo clippy + --all-features + --message-format=json | clippy-sarif | tee rust-clippy-results.sarif | sarif-fmt + continue-on-error: true + + - name: Upload analysis results to GitHub + uses: github/codeql-action/upload-sarif@8f1a6fed33af5212fab8a999d004627ae8901d1b + with: + sarif_file: rust-clippy-results.sarif + wait-for-processing: true From 2712bde88f992c653ecf230aea52c0c1bae02521 Mon Sep 17 00:00:00 2001 From: egibs <20933572+egibs@users.noreply.github.com> Date: Sun, 9 Jun 2024 12:37:54 -0500 Subject: [PATCH 2/3] Appease the linter Signed-off-by: egibs <20933572+egibs@users.noreply.github.com> --- src/main.rs | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/main.rs b/src/main.rs index 9780dcc..0471f76 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,6 +2,7 @@ use std::env; use std::fs::File; use std::io::{Read, Seek, SeekFrom}; use std::process; +use std::fmt::Write; mod display; @@ -30,10 +31,10 @@ fn main() { } let magic = &header[..4]; - let magic_string = magic - .iter() - .map(|b| format!("{:02X}", b)) - .collect::(); + let magic_string = magic.iter().fold(String::new(), |mut result, b| { + let _ = write!(result, "{b:02X}"); + result + }); // Check if the file is an ELF file if magic != ELF_MAGIC { @@ -311,9 +312,9 @@ fn get_segment_type(segment_type: u32) -> &'static str { fn get_segment_flags(segment_flags: u32) -> String { let mut flags = String::new(); match segment_flags { - 0x01 => flags.push_str("R"), - 0x02 => flags.push_str("W"), - 0x04 => flags.push_str("X"), + 0x01 => flags.push('R'), + 0x02 => flags.push('W'), + 0x04 => flags.push('X'), _ => flags.push_str("Unknown"), } flags @@ -367,11 +368,9 @@ fn get_data_encoding(header: &[u8]) -> (String, u8) { } fn bits_to_u16(bits: &[u8; 2]) -> u16 { - let value = u16::from_le_bytes(*bits); - value + u16::from_le_bytes(*bits) } fn get_elf_version(header: &[u8]) -> u8 { - let elf_version = header[0x06]; - elf_version + header[0x06] } From 94686f7c05e4cd3041b3fe0f00c803c665476998 Mon Sep 17 00:00:00 2001 From: egibs <20933572+egibs@users.noreply.github.com> Date: Sun, 9 Jun 2024 12:40:52 -0500 Subject: [PATCH 3/3] fmt Signed-off-by: egibs <20933572+egibs@users.noreply.github.com> --- src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 0471f76..bde8613 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,8 +1,8 @@ use std::env; +use std::fmt::Write; use std::fs::File; use std::io::{Read, Seek, SeekFrom}; use std::process; -use std::fmt::Write; mod display;