Skip to content

Commit d5807fb

Browse files
authored
Merge pull request #1996 from evgenyz/fix-sysctl-offline
OVAL/sysctl: Fix offline mode
2 parents 4704813 + 7bf6811 commit d5807fb

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

src/OVAL/probes/unix/sysctl_probe.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,14 @@ int sysctl_probe_main(probe_ctx *ctx, void *probe_arg)
150150
while ((ofts_ent = oval_fts_read(ofts)) != NULL) {
151151
SEXP_t *se_mib;
152152
char mibpath[PATH_MAX], *mib;
153-
size_t miblen;
153+
size_t miblen, mibstart;
154154
struct stat file_stat;
155155

156-
snprintf(mibpath, sizeof mibpath, "%s/%s", ofts_ent->path, ofts_ent->file);
156+
if (prefix != NULL) {
157+
snprintf(mibpath, sizeof mibpath, "%s/%s/%s", prefix, ofts_ent->path, ofts_ent->file);
158+
} else {
159+
snprintf(mibpath, sizeof mibpath, "%s/%s", ofts_ent->path, ofts_ent->file);
160+
}
157161

158162
/* Skip write-only files, eg. /proc/sys/net/ipv4/route/flush */
159163
if (stat(mibpath, &file_stat) == -1) {
@@ -168,7 +172,10 @@ int sysctl_probe_main(probe_ctx *ctx, void *probe_arg)
168172
continue;
169173
}
170174

171-
mib = strdup(mibpath + strlen(PROC_SYS_DIR) + 1);
175+
mibstart = 0;
176+
mibstart += prefix != NULL ? strlen(prefix)+1 : 0;
177+
mibstart += strlen(PROC_SYS_DIR)+1;
178+
mib = strdup(mibpath + mibstart);
172179
miblen = strlen(mib);
173180

174181
while (miblen > 0) {

tests/probes/sysctl/test_sysctl_probe_offline_mode.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@ function perform_test {
1010

1111
result=`mktemp`
1212
stderr=`mktemp`
13-
hostname=`hostname`
13+
hostname="fake.host.name.me"
1414

1515
tmpdir=$(make_temp_dir /tmp "test_offline_mode_sysctl")
16-
ln -s -t "${tmpdir}" "/proc"
16+
mkdir -p "${tmpdir}/proc/sys/kernel"
17+
echo "${hostname}" > "${tmpdir}/proc/sys/kernel/hostname"
1718
set_chroot_offline_test_mode "${tmpdir}"
1819

1920
$OSCAP oval eval --results $result $srcdir/test_sysctl_probe.oval.xml 2>$stderr

0 commit comments

Comments
 (0)