Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
rule_field_matches_string failed because it relied on UB as discussed in #1171
  • Loading branch information
bynect committed Jan 24, 2025
1 parent 298c3a7 commit 03303ab
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 4 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ jobs:
env:
CC: gcc
EXTRA_CFLAGS: "-Werror"
MAKE: gmake

steps:
- uses: actions/checkout@v4
Expand All @@ -82,7 +83,7 @@ jobs:
- name: Test in FreeBSD
uses: vmactions/freebsd-vm@v1
with:
envs: "CC EXTRA_CFLAGS"
envs: "CC EXTRA_CFLAGS MAKE"
usesh: true
sync: rsync
copyback: false
Expand All @@ -101,7 +102,7 @@ jobs:
./test/test-install.sh
echo "* Run valgrind test"
gmake clean && gmake -j test-valgrind
gmake -j test-valgrind
doxygen:
steps:
Expand Down
1 change: 1 addition & 0 deletions src/rules.c
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ static inline bool rule_field_matches_string(const char *value, const char *patt
}
regex_t regex;

// TODO check if regex pattern is not empty
// TODO compile each regex only once
int err = regcomp(&regex, pattern, REG_NEWLINE | REG_EXTENDED | REG_NOSUB);
if (err) {
Expand Down
1 change: 0 additions & 1 deletion test/rules.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ TEST test_pattern_match(void) {
ASSERT(rule_field_matches_string("ffffasd", ".*asd"));

// Substring matching
ASSERT(rule_field_matches_string("asd", ""));
ASSERT(rule_field_matches_string("asd", "sd"));
ASSERT(rule_field_matches_string("asd", "a"));
ASSERT(rule_field_matches_string("asd", "d"));
Expand Down
4 changes: 3 additions & 1 deletion test/test-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
# Throw error any time a command fails
set -euo pipefail

MAKE=${MAKE:-make}

# Export parameters so they are useable by subshells and make
export BASE="$(dirname "$(dirname "$(readlink -f "$0")")")"
export DESTDIR="${BASE}/install"
Expand All @@ -14,7 +16,7 @@ export SERVICEDIR_SYSTEMD="/systemd"
export SERVICEDIR_DBUS="/dbus"

do_make() { # for convenience/conciseness
make -C "${BASE}" "$@"
${MAKE} -C "${BASE}" "$@"
}

check_dest() {
Expand Down

0 comments on commit 03303ab

Please sign in to comment.