Skip to content

Commit c0f12bb

Browse files
committed
[New] Portable exec tests; unset LMD_BASEDIR after use; CHANGELOG sync
[New] tests/36-portable-exec.bats: 10 tests for source-tree auto-detect, LMD_BASEDIR override, symlink resolution, installed-path regression [Fix] Unset LMD_BASEDIR after consumption to prevent leakage to child processes [Fix] CHANGELOG/CHANGELOG.RELEASE: add 5 missing entries (alert templates, pkg_lib v1.0.6, batsman v1.3.0, CSIG compiler, portable exec); correct stale vendored lib versions (pkg_lib v1.0.5→v1.0.6, batsman v1.2.2→v1.3.0)
1 parent 9a63edb commit c0f12bb

4 files changed

Lines changed: 92 additions & 2 deletions

File tree

CHANGELOG

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,16 @@ v2.0.1 | Mar 25 2026:
5151
[New] Symlink farm enforcement: static manifest ships with RPM/DEB; pkg_fhs_verify_farm
5252
auto-detects and repairs broken symlinks at startup
5353
[New] FHS fallback sourcing: maldet boots from /usr/lib/maldet when legacy symlinks broken
54+
[New] Portable source-tree execution: run maldet directly from git clone or tarball without
55+
install.sh; auto-detects inspath from script location; LMD_BASEDIR env override
5456

5557
-- Changes --
5658

59+
[Change] Alert templates: consolidate summary into header templates; add quarantine metrics
60+
to scan and panel templates
61+
[Change] Update pkg_lib.sh to v1.0.6: symlink farm enforcement
62+
[Change] Update batsman submodule to v1.3.0: GNU parallel support, BATS --jobs
63+
5764
[Change] Hook scans write to rolling hook.hits.log instead of creating session files;
5865
genalert suppressed for hook scans
5966
[Change] HTML email rendered on-demand at send time from current templates; persistent
@@ -73,7 +80,7 @@ v2.0.1 | Mar 25 2026:
7380
[Change] inotify_verbose per-file ClamAV logging deprecated; batch engine log
7481
messages supersede
7582
[Change] Vendored libraries updated: tlog_lib v2.0.4, elog_lib v1.0.4, alert_lib
76-
v1.0.5, pkg_lib v1.0.5; batsman submodule v1.2.2
83+
v1.0.5, pkg_lib v1.0.6; batsman submodule v1.3.0
7784
[Change] Scan engine: HEX+CSIG merged into single worker pass; scan stage reorder
7885
(strlen runs last); bulk awk HEX classifier
7986
[Change] gensigs: awk compiler replaces bash+sed wildcard/csig loops; dead helpers removed
@@ -83,6 +90,7 @@ v2.0.1 | Mar 25 2026:
8390

8491
-- Bug Fixes --
8592

93+
[Fix] CSIG compiler: reject invalid && separator and universal subsigs in OR groups
8694
[Fix] pkg/Makefile: VERSION extraction, test target Dockerfile paths
8795
[Fix] install.sh: detect supervisor and legacy monitor; graceful stop+restart on upgrade
8896
[Fix] -co/--config-option now position-independent; in-memory parser replaces tmpfile+sed

CHANGELOG.RELEASE

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,16 @@ v2.0.1 | Mar 25 2026:
5151
[New] Symlink farm enforcement: static manifest ships with RPM/DEB; pkg_fhs_verify_farm
5252
auto-detects and repairs broken symlinks at startup
5353
[New] FHS fallback sourcing: maldet boots from /usr/lib/maldet when legacy symlinks broken
54+
[New] Portable source-tree execution: run maldet directly from git clone or tarball without
55+
install.sh; auto-detects inspath from script location; LMD_BASEDIR env override
5456

5557
-- Changes --
5658

59+
[Change] Alert templates: consolidate summary into header templates; add quarantine metrics
60+
to scan and panel templates
61+
[Change] Update pkg_lib.sh to v1.0.6: symlink farm enforcement
62+
[Change] Update batsman submodule to v1.3.0: GNU parallel support, BATS --jobs
63+
5764
[Change] Hook scans write to rolling hook.hits.log instead of creating session files;
5865
genalert suppressed for hook scans
5966
[Change] HTML email rendered on-demand at send time from current templates; persistent
@@ -73,7 +80,7 @@ v2.0.1 | Mar 25 2026:
7380
[Change] inotify_verbose per-file ClamAV logging deprecated; batch engine log
7481
messages supersede
7582
[Change] Vendored libraries updated: tlog_lib v2.0.4, elog_lib v1.0.4, alert_lib
76-
v1.0.5, pkg_lib v1.0.5; batsman submodule v1.2.2
83+
v1.0.5, pkg_lib v1.0.6; batsman submodule v1.3.0
7784
[Change] Scan engine: HEX+CSIG merged into single worker pass; scan stage reorder
7885
(strlen runs last); bulk awk HEX classifier
7986
[Change] gensigs: awk compiler replaces bash+sed wildcard/csig loops; dead helpers removed
@@ -83,6 +90,7 @@ v2.0.1 | Mar 25 2026:
8390

8491
-- Bug Fixes --
8592

93+
[Fix] CSIG compiler: reject invalid && separator and universal subsigs in OR groups
8694
[Fix] pkg/Makefile: VERSION extraction, test target Dockerfile paths
8795
[Fix] install.sh: detect supervisor and legacy monitor; graceful stop+restart on upgrade
8896
[Fix] -co/--config-option now position-independent; in-memory parser replaces tmpfile+sed

files/maldet

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ else
2323
fi
2424
unset _self _selfdir
2525
fi
26+
unset LMD_BASEDIR # consumed; prevent leakage to child processes (e.g. maldet -b)
2627
intcnf="$inspath/internals/internals.conf"
2728
if [ -f "/etc/sysconfig/maldet" ]; then
2829
syscnf=/etc/sysconfig/maldet

tests/36-portable-exec.bats

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#!/usr/bin/env bats
2+
3+
load '/usr/local/lib/bats/bats-support/load'
4+
load '/usr/local/lib/bats/bats-assert/load'
5+
6+
LMD_INSTALL="/usr/local/maldetect"
7+
8+
# --- Source-tree auto-detect ---
9+
10+
@test "portable: internals.conf uses conditional inspath assignment" {
11+
grep -q 'inspath="\${inspath:-/usr/local/maldetect}"' "$LMD_INSTALL/internals/internals.conf"
12+
}
13+
14+
@test "portable: maldet resolves inspath from own directory" {
15+
# When invoked via absolute path, auto-detect finds internals/ beside the script
16+
run bash -c '_self=$(readlink -f "'"$LMD_INSTALL/maldet"'" 2>/dev/null); _selfdir="${_self%/*}"; [ -f "$_selfdir/internals/internals.conf" ] && echo "found" || echo "missing"'
17+
assert_output "found"
18+
}
19+
20+
@test "portable: default inspath resolves to /usr/local/maldetect" {
21+
run maldet --version
22+
assert_success
23+
assert_output --partial "Linux Malware Detect"
24+
}
25+
26+
# --- LMD_BASEDIR env override ---
27+
28+
@test "portable: LMD_BASEDIR overrides inspath" {
29+
run env LMD_BASEDIR="$LMD_INSTALL" maldet --version
30+
assert_success
31+
assert_output --partial "Linux Malware Detect"
32+
}
33+
34+
@test "portable: LMD_BASEDIR with invalid path fails gracefully" {
35+
run env LMD_BASEDIR="/nonexistent" maldet --version
36+
assert_failure
37+
assert_output --partial "intcnf not found"
38+
}
39+
40+
@test "portable: LMD_BASEDIR is unset after consumption" {
41+
# LMD_BASEDIR should not leak to child processes
42+
grep -q 'unset LMD_BASEDIR' "$LMD_INSTALL/maldet"
43+
}
44+
45+
# --- Symlink resolution ---
46+
47+
@test "portable: symlink to maldet resolves to real path" {
48+
local _tmplink
49+
_tmplink=$(mktemp -u /tmp/maldet-symlink-XXXXXX)
50+
ln -s "$LMD_INSTALL/maldet" "$_tmplink"
51+
run "$_tmplink" --version
52+
rm -f "$_tmplink"
53+
assert_success
54+
assert_output --partial "Linux Malware Detect"
55+
}
56+
57+
# --- Regression: installed path unaffected ---
58+
59+
@test "portable: installed maldet still uses /usr/local/maldetect paths" {
60+
# Verify that session dir resolves under the install path
61+
run bash -c 'source '"$LMD_INSTALL"'/internals/internals.conf; echo "$sessdir"'
62+
assert_output "/usr/local/maldetect/sess"
63+
}
64+
65+
@test "portable: internals.conf preserves pre-set inspath" {
66+
run bash -c 'inspath="/custom/path"; source '"$LMD_INSTALL"'/internals/internals.conf; echo "$inspath"'
67+
assert_output "/custom/path"
68+
}
69+
70+
@test "portable: internals.conf defaults when inspath is unset" {
71+
run bash -c 'unset inspath; source '"$LMD_INSTALL"'/internals/internals.conf; echo "$inspath"'
72+
assert_output "/usr/local/maldetect"
73+
}

0 commit comments

Comments
 (0)