Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run fuzzer in CI #93

Merged
merged 3 commits into from
Mar 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions .github/workflows/fuzz.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Fuzz

on: [push, pull_request]

jobs:

fuzz:
if: ${{ !github.event.act }}
runs-on: ubuntu-20.04
strategy:
fail-fast: false
matrix:
fuzz_target: [decode_rnd, encode_decode]
steps:
- name: Install test dependencies
run: sudo apt-get update -y && sudo apt-get install -y binutils-dev libunwind8-dev libcurl4-openssl-dev libelf-dev libdw-dev cmake gcc libiberty-dev
- uses: actions/checkout@v2
- uses: actions/cache@v2
id: cache-fuzz
with:
path: |
~/.cargo/bin
fuzz/target
target
key: cache-${{ matrix.target }}-${{ hashFiles('**/Cargo.toml','**/Cargo.lock') }}
- name: Checkout Toolchain
uses: dtolnay/rust-toolchain@stable
- name: fuzz
run: cd fuzz && ./fuzz.sh "${{ matrix.fuzz_target }}"
- run: echo "${{ matrix.fuzz_target }}.rs" >executed_${{ matrix.fuzz_target }}
- uses: actions/upload-artifact@v2
with:
name: executed_${{ matrix.fuzz_target }}
path: executed_${{ matrix.fuzz_target }}

verify-execution:
if: ${{ !github.event.act }}
needs: fuzz
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/download-artifact@v2
- name: Display structure of downloaded files
run: ls -R
- run: find executed_* -type f -exec cat {} + | sort > executed
- run: ls fuzz/fuzz_targets | sort > expected
- run: diff expected executed
2 changes: 1 addition & 1 deletion fuzz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ afl_fuzz = ["afl"]
honggfuzz_fuzz = ["honggfuzz"]

[dependencies]
honggfuzz = { version = "0.5", optional = true }
honggfuzz = { version = "0.5", default-features = false, optional = true }
afl = { version = "0.3", optional = true }
libc = "0.2"
bech32 = { path = ".." }
Expand Down
2 changes: 1 addition & 1 deletion fuzz/travis-fuzz.sh → fuzz/fuzz.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash
set -e
cargo install --force honggfuzz
cargo install --force honggfuzz --no-default-features
for TARGET in fuzz_targets/*; do
FILENAME=$(basename $TARGET)
FILE="${FILENAME%.*}"
Expand Down
4 changes: 2 additions & 2 deletions fuzz/fuzz_targets/encode_decode.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
extern crate bech32;

use std::str::FromStr;
use std::convert::TryFrom;

fn do_test(data: &[u8]) {
if data.len() < 1 {
Expand All @@ -19,7 +19,7 @@ fn do_test(data: &[u8]) {

let dp = data[hrp_end..]
.iter()
.map(|b| bech32::u5::try_from_u8(b % 32).unwrap())
.map(|b| bech32::u5::try_from(b % 32).unwrap())
.collect::<Vec<_>>();

let variant = if data[0] > 0x0f {
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,9 +415,9 @@ fn check_hrp(hrp: &str) -> Result<Case, Error> {
return Err(Error::InvalidChar(b as char));
}

if (b'a'..=b'z').contains(&b) {
if b.is_ascii_lowercase() {
has_lower = true;
} else if (b'A'..=b'Z').contains(&b) {
} else if b.is_ascii_uppercase() {
has_upper = true;
};

Expand Down