Skip to content

Commit 6506089

Browse files
authored
Merge pull request #2080 from jan-cerny/issue_2076
Improve counting collected items
2 parents e539163 + 3ce4482 commit 6506089

File tree

3 files changed

+5
-10
lines changed

3 files changed

+5
-10
lines changed

src/OVAL/probes/probe/icache.c

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -570,19 +570,11 @@ static int _mark_collected_object_as_incomplete(struct probe_ctx *ctx, const cha
570570
*/
571571
int probe_item_collect(struct probe_ctx *ctx, SEXP_t *item)
572572
{
573-
SEXP_t *cobj_content;
574-
size_t cobj_itemcnt;
575-
int memcheck_ret;
576-
577573
if (ctx == NULL || ctx->probe_out == NULL || item == NULL) {
578574
return -1;
579575
}
580576

581-
cobj_content = SEXP_listref_nth(ctx->probe_out, 3);
582-
cobj_itemcnt = SEXP_list_length(cobj_content);
583-
SEXP_free(cobj_content);
584-
585-
if (ctx->max_collected_items != OSCAP_PROBE_COLLECT_UNLIMITED && cobj_itemcnt >= ctx->max_collected_items) {
577+
if (ctx->max_collected_items != OSCAP_PROBE_COLLECT_UNLIMITED && ctx->collected_items >= ctx->max_collected_items) {
586578
char *message = oscap_sprintf("Object is incomplete because the object matches more than %ld items.", ctx->max_collected_items);
587579
if (_mark_collected_object_as_incomplete(ctx, message) != 0) {
588580
free(message);
@@ -592,7 +584,7 @@ int probe_item_collect(struct probe_ctx *ctx, SEXP_t *item)
592584
return 2;
593585
}
594586

595-
memcheck_ret = probe_cobj_memcheck(cobj_itemcnt, ctx->max_mem_ratio);
587+
int memcheck_ret = probe_cobj_memcheck(ctx->collected_items, ctx->max_mem_ratio);
596588
if (memcheck_ret == -1) {
597589
dE("Failed to check available memory");
598590
SEXP_free(item);
@@ -619,6 +611,7 @@ int probe_item_collect(struct probe_ctx *ctx, SEXP_t *item)
619611
return (-1);
620612
}
621613

614+
ctx->collected_items++;
622615
return (0);
623616
}
624617

src/OVAL/probes/probe/probe.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ struct probe_ctx {
9393
probe_icache_t *icache; /**< item cache */
9494
int offline_mode;
9595
double max_mem_ratio;
96+
size_t collected_items;
9697
size_t max_collected_items;
9798
struct oscap_list *blocked_paths;
9899
};

src/OVAL/probes/probe/worker.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,6 +1091,7 @@ SEXP_t *probe_worker(probe_t *probe, SEAP_msg_t *msg_in, int *ret)
10911091
if (max_ratio > 0)
10921092
pctx.max_mem_ratio = max_ratio;
10931093
}
1094+
pctx.collected_items = 0;
10941095
pctx.max_collected_items = OSCAP_PROBE_COLLECT_UNLIMITED;
10951096
char *max_collected_items_str = getenv("OSCAP_PROBE_MAX_COLLECTED_ITEMS");
10961097
if (max_collected_items_str != NULL) {

0 commit comments

Comments
 (0)