Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve counting collected items #2080

Merged
merged 1 commit into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 3 additions & 10 deletions src/OVAL/probes/probe/icache.c
Original file line number Diff line number Diff line change
Expand Up @@ -570,19 +570,11 @@ static int _mark_collected_object_as_incomplete(struct probe_ctx *ctx, const cha
*/
int probe_item_collect(struct probe_ctx *ctx, SEXP_t *item)
{
SEXP_t *cobj_content;
size_t cobj_itemcnt;
int memcheck_ret;

if (ctx == NULL || ctx->probe_out == NULL || item == NULL) {
return -1;
}

cobj_content = SEXP_listref_nth(ctx->probe_out, 3);
cobj_itemcnt = SEXP_list_length(cobj_content);
SEXP_free(cobj_content);

if (ctx->max_collected_items != OSCAP_PROBE_COLLECT_UNLIMITED && cobj_itemcnt >= ctx->max_collected_items) {
if (ctx->max_collected_items != OSCAP_PROBE_COLLECT_UNLIMITED && ctx->collected_items >= ctx->max_collected_items) {
char *message = oscap_sprintf("Object is incomplete because the object matches more than %ld items.", ctx->max_collected_items);
if (_mark_collected_object_as_incomplete(ctx, message) != 0) {
free(message);
Expand All @@ -592,7 +584,7 @@ int probe_item_collect(struct probe_ctx *ctx, SEXP_t *item)
return 2;
}

memcheck_ret = probe_cobj_memcheck(cobj_itemcnt, ctx->max_mem_ratio);
int memcheck_ret = probe_cobj_memcheck(ctx->collected_items, ctx->max_mem_ratio);
if (memcheck_ret == -1) {
dE("Failed to check available memory");
SEXP_free(item);
Expand All @@ -619,6 +611,7 @@ int probe_item_collect(struct probe_ctx *ctx, SEXP_t *item)
return (-1);
}

ctx->collected_items++;
return (0);
}

Expand Down
1 change: 1 addition & 0 deletions src/OVAL/probes/probe/probe.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ struct probe_ctx {
probe_icache_t *icache; /**< item cache */
int offline_mode;
double max_mem_ratio;
size_t collected_items;
size_t max_collected_items;
struct oscap_list *blocked_paths;
};
Expand Down
1 change: 1 addition & 0 deletions src/OVAL/probes/probe/worker.c
Original file line number Diff line number Diff line change
Expand Up @@ -1091,6 +1091,7 @@ SEXP_t *probe_worker(probe_t *probe, SEAP_msg_t *msg_in, int *ret)
if (max_ratio > 0)
pctx.max_mem_ratio = max_ratio;
}
pctx.collected_items = 0;
pctx.max_collected_items = OSCAP_PROBE_COLLECT_UNLIMITED;
char *max_collected_items_str = getenv("OSCAP_PROBE_MAX_COLLECTED_ITEMS");
if (max_collected_items_str != NULL) {
Expand Down
Loading