Skip to content

Commit f2461c7

Browse files
committed
Make probe items limit configurable
Users can limit the amount of items collected by setting the `OSCAP_PROBE_MAX_COLLECTED_ITEMS` environment variable. By default, the amount of items is unlimited.
1 parent 176f1a8 commit f2461c7

File tree

5 files changed

+21
-12
lines changed

5 files changed

+21
-12
lines changed

docs/manual/manual.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1618,6 +1618,7 @@ not considered local by the scanner:
16181618
* `SEXP_VALIDATE_DISABLE` - If set, `oscap` will not validate SEXP expressions during its execution.
16191619
* `SOURCE_DATE_EPOCH` - Timestamp in seconds since epoch. This timestamp will be used instead of the current time to populate `timestamp` attributes in SCAP source data streams created by `oscap ds sds-compose` sub-module. This is used for reproducible builds of data streams.
16201620
* `OSCAP_PROBE_MEMORY_USAGE_RATIO` - maximum memory usage ratio (used/total) for OpenSCAP probes, default: 0.1
1621+
* `OSCAP_PROBE_MAX_COLLECTED_ITEMS` - maximal count of collected items by OpenSCAP probe for a single OVAL object evaluation
16211622

16221623
Also, OpenSCAP uses `libcurl` library which also can be configured using environment variables. See https://curl.se/libcurl/c/libcurl-env.html[the list of libcurl environment variables].
16231624

src/OVAL/probes/probe/icache.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@
4545
#include "icache.h"
4646
#include "_sexp-ID.h"
4747

48-
#define PROBE_ITEM_COLLECT_MAX 1000
49-
5048
static volatile uint32_t next_ID = 0;
5149

5250
#if !defined(HAVE_ATOMIC_FUNCTIONS)
@@ -585,8 +583,8 @@ int probe_item_collect(struct probe_ctx *ctx, SEXP_t *item)
585583
cobj_itemcnt = SEXP_list_length(cobj_content);
586584
SEXP_free(cobj_content);
587585

588-
if (cobj_itemcnt >= PROBE_ITEM_COLLECT_MAX) {
589-
char *message = oscap_sprintf("Object is incomplete because the object matches more than %d items.", PROBE_ITEM_COLLECT_MAX);
586+
if (ctx->max_collected_items != OSCAP_PROBE_COLLECT_UNLIMITED && cobj_itemcnt >= ctx->max_collected_items) {
587+
char *message = oscap_sprintf("Object is incomplete because the object matches more than %ld items.", ctx->max_collected_items);
590588
if (_mark_collected_object_as_incomplete(ctx, message) != 0) {
591589
free(message);
592590
return -1;

src/OVAL/probes/probe/probe.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@
4343
#include "common/util.h"
4444
#include "common/compat_pthread_barrier.h"
4545

46+
/* default max. memory usage ratio - used/total */
47+
/* can be overridden by environment variable OSCAP_PROBE_MEMORY_USAGE_RATIO */
48+
#define OSCAP_PROBE_MEMORY_USAGE_RATIO_DEFAULT 0.33
49+
#define OSCAP_PROBE_COLLECT_UNLIMITED 0
50+
4651
typedef struct {
4752
pthread_rwlock_t rwlock;
4853
uint32_t flags;
@@ -84,6 +89,7 @@ struct probe_ctx {
8489
probe_icache_t *icache; /**< item cache */
8590
int offline_mode;
8691
double max_mem_ratio;
92+
size_t max_collected_items;
8793
};
8894

8995
typedef enum {

src/OVAL/probes/probe/worker.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,6 @@ extern int chroot(const char *);
5252
#include "probe-table.h"
5353
#include "probe.h"
5454

55-
/* default max. memory usage ratio - used/total */
56-
/* can be overridden by environment variable OSCAP_PROBE_MEMORY_USAGE_RATIO */
57-
#define OSCAP_PROBE_MEMORY_USAGE_RATIO_DEFAULT 0.33
58-
5955
extern bool OSCAP_GSYM(varref_handling);
6056
extern void *OSCAP_GSYM(probe_arg);
6157

@@ -1078,6 +1074,14 @@ SEXP_t *probe_worker(probe_t *probe, SEAP_msg_t *msg_in, int *ret)
10781074
if (max_ratio > 0)
10791075
pctx.max_mem_ratio = max_ratio;
10801076
}
1077+
pctx.max_collected_items = OSCAP_PROBE_COLLECT_UNLIMITED;
1078+
char *max_collected_items_str = getenv("OSCAP_PROBE_MAX_COLLECTED_ITEMS");
1079+
if (max_collected_items_str != NULL) {
1080+
int max_collected_items = strtol(max_collected_items_str, NULL, 0);
1081+
if (max_collected_items > 0) {
1082+
pctx.max_collected_items = max_collected_items;
1083+
}
1084+
}
10811085

10821086
/* simple object */
10831087
pctx.icache = probe->icache;

tests/memory/collect_limit.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ set -e -o pipefail
44

55
. $builddir/tests/test_common.sh
66

7-
# PROBE_ITEM_COLLECT_MAX limit is 1000
8-
seq 1010 > /tmp/longfile
7+
export OSCAP_PROBE_MAX_COLLECTED_ITEMS=100
8+
seq 110 > /tmp/longfile
99
result=$(mktemp)
1010
$OSCAP oval eval --results "$result" $srcdir/collect_limit.oval.xml
1111
assert_exists 1 '/oval_results/results/system/oval_system_characteristics/collected_objects/object'
1212
assert_exists 1 '/oval_results/results/system/oval_system_characteristics/collected_objects/object[@flag="incomplete"]'
1313
assert_exists 1 '/oval_results/results/system/oval_system_characteristics/collected_objects/object/message[@level="warning"]'
14-
text="Object is incomplete because the object matches more than 1000 items."
14+
text="Object is incomplete because the object matches more than 100 items."
1515
assert_exists 1 "/oval_results/results/system/oval_system_characteristics/collected_objects/object/message[text()=\"$text\"]"
16-
assert_exists 1000 '/oval_results/results/system/oval_system_characteristics/system_data/ind-sys:textfilecontent_item'
16+
assert_exists 100 '/oval_results/results/system/oval_system_characteristics/system_data/ind-sys:textfilecontent_item'
1717
rm -f /tmp/longfile
1818
rm -f "$result"

0 commit comments

Comments
 (0)