Skip to content

Commit 81287e2

Browse files
authored
ELF: sort array of fortifiable functions (#34)
* ELF: add unit test for sorted fortifiable functions array Test that the array of fortifiable functions is sorted to ensure a correctly working binary search. * ELF: sort array of fortifiable functions
1 parent eb359d0 commit 81287e2

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,4 @@ jobs:
7070
- run: cargo build --no-default-features --features elf
7171
- run: cargo build --no-default-features --features pe
7272
- run: cargo build --no-default-features --features macho
73+
- run: cargo test

src/elf.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,13 +324,13 @@ const FORTIFIABLE_FUNCTIONS: [&str; 79] = [
324324
"obstack_vprintf",
325325
"poll",
326326
"ppoll",
327-
"pread64",
328327
"pread",
328+
"pread64",
329329
"printf",
330330
"ptsname_r",
331331
"read",
332-
"readlinkat",
333332
"readlink",
333+
"readlinkat",
334334
"realpath",
335335
"recv",
336336
"recvfrom",
@@ -539,3 +539,16 @@ impl Properties for Elf<'_> {
539539
None
540540
}
541541
}
542+
543+
#[cfg(test)]
544+
mod tests {
545+
use super::FORTIFIABLE_FUNCTIONS;
546+
547+
#[test]
548+
fn test_sorted_fortifiable_functions() {
549+
assert!(FORTIFIABLE_FUNCTIONS.windows(2).all(|f| {
550+
println!("{} ? {}", f[0], f[1]);
551+
f[0] < f[1]
552+
}));
553+
}
554+
}

0 commit comments

Comments
 (0)