<commit_before>/**
 * @file oval_resultSystem.c
 * \brief Open Vulnerability and Assessment Language
 *
 * See more details at http://oval.mitre.org/
 */

/*
 * Copyright 2009--2013 Red Hat Inc., Durham, North Carolina.
 * All Rights Reserved.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * Authors:
 *      "<NAME>" <<EMAIL>>
 *      "<NAME>" <<EMAIL>>
 *      <NAME>
 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#include "oval_definitions.h"
#include "oval_agent_api.h"
#include "oval_agent_api_impl.h"
#include "oval_results_impl.h"
#include "adt/oval_collection_impl.h"
#include "adt/oval_smc_impl.h"
#include "adt/oval_smc_iterator_impl.h"
#include "adt/oval_string_map_impl.h"
#include "oval_parser_impl.h"

#include "common/debug_priv.h"
#include "common/_error.h"
#include "common/util.h"

typedef struct oval_result_system {
	struct oval_results_model *model;
	struct oval_smc *definitions;			///< Map contains lists of oval_result_definition
	struct oval_smc *tests;				///< Map contains lists of oval_result_test
	struct oval_syschar_model *syschar_model;
} oval_result_system_t;


static void _oval_result_system_scan_criteria_for_references(struct oval_result_criteria_node *node, 
							     struct oval_smc *testmap);

static void _oval_result_system_scan_entity_for_references(struct oval_syschar_model *syschar_model, 
							   struct oval_entity *entity,
							   struct oval_string_map *objmap,
							   struct oval_string_map *sttmap, 
							   struct oval_string_map *varmap, 
							   struct oval_string_map *sysmap);

static void _oval_result_system_scan_set_for_references(struct oval_syschar_model *syschar_model, 
							struct oval_setobject *set,
							struct oval_string_map *objmap,
							struct oval_string_map *sttmap, 
							struct oval_string_map *varmap, 
							struct oval_string_map *sysmap);

static void _oval_result_system_scan_object_for_references(struct oval_syschar_model *syschar_model, 
							struct oval_object *object,
							struct oval_string_map *objmap,
							struct oval_string_map *sttmap, 
							struct oval_string_map *varmap, 
							struct oval_string_map *sysmap);
static void _oval_result_system_scan_state_for_references(struct oval_syschar_model *syschar_model, 
							struct oval_state *state,
							struct oval_string_map *objmap,
							struct oval_string_map *sttmap, 
							struct oval_string_map *varmap, 
							struct oval_string_map *sysmap);

static void _oval_result_system_scan_component_for_references(struct oval_syschar_model *syschar_model, 
							struct oval_component *component,	
							struct oval_string_map *objmap,
							struct oval_string_map *sttmap, 
							struct oval_string_map *varmap, 
							struct oval_string_map *sysmap);

static bool _oval_result_system_resolve_syschar(struct oval_syschar *syschar, struct oval_string_map *sysmap);





struct oval_result_system *oval_result_system_new(struct oval_results_model *model,
						  struct oval_syschar_model *syschar_model)
{
	__attribute__nonnull__(model);
	oval_result_system_t *sys;

	sys = (oval_result_system_t *) oscap_alloc(sizeof(oval_result_system_t));
	if (sys == NULL)
		return NULL;

	sys->definitions = oval_smc_new();
	sys->tests = oval_smc_new();
	sys->syschar_model = syschar_model;
	sys->model = model;

	oval_results_model_add_system(model, sys);

	return sys;
}

struct oval_result_system *oval_result_system_clone(struct oval_results_model *new_model,
						    struct oval_result_system *old_system)
{
	__attribute__nonnull__(old_system);

	struct oval_result_system *new_system =
	    oval_result_system_new(new_model, oval_result_system_get_syschar_model(old_system));

	// TODO: This one seems to leak, but it did so from day 0
	oval_smc_clone_user(old_system->definitions, (oval_smc_user_clone_func) oval_result_definition_clone, new_system);
	oval_smc_clone_user(old_system->tests, (oval_smc_user_clone_func) oval_result_test_clone, new_system);

	return new_system;
}

void oval_result_system_free(struct oval_result_system *sys)
{<commit_msg>Fix the leakage in result_system_clone()<commit_after>/**
 * @file oval_resultSystem.c
 * \brief Open Vulnerability and Assessment Language
 *
 * See more details at http://oval.mitre.org/
 */

/*
 * Copyright 2009--2013 Red Hat Inc., Durham, North Carolina.
 * All Rights Reserved.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * Authors:
 *      "<NAME>" <<EMAIL>>
 *      "<NAME>" <<EMAIL>>
 *      <NAME>
 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#include "oval_definitions.h"
#include "oval_agent_api.h"
#include "oval_agent_api_impl.h"
#include "oval_results_impl.h"
#include "adt/oval_collection_impl.h"
#include "adt/oval_smc_impl.h"
#include "adt/oval_smc_iterator_impl.h"
#include "adt/oval_string_map_impl.h"
#include "oval_parser_impl.h"

#include "common/debug_priv.h"
#include "common/_error.h"
#include "common/util.h"

typedef struct oval_result_system {
	struct oval_results_model *model;
	struct oval_smc *definitions;			///< Map contains lists of oval_result_definition
	struct oval_smc *tests;				///< Map contains lists of oval_result_test
	struct oval_syschar_model *syschar_model;
} oval_result_system_t;


static void _oval_result_system_scan_criteria_for_references(struct oval_result_criteria_node *node, 
							     struct oval_smc *testmap);

static void _oval_result_system_scan_entity_for_references(struct oval_syschar_model *syschar_model, 
							   struct oval_entity *entity,
							   struct oval_string_map *objmap,
							   struct oval_string_map *sttmap, 
							   struct oval_string_map *varmap, 
							   struct oval_string_map *sysmap);

static void _oval_result_system_scan_set_for_references(struct oval_syschar_model *syschar_model, 
							struct oval_setobject *set,
							struct oval_string_map *objmap,
							struct oval_string_map *sttmap, 
							struct oval_string_map *varmap, 
							struct oval_string_map *sysmap);

static void _oval_result_system_scan_object_for_references(struct oval_syschar_model *syschar_model, 
							struct oval_object *object,
							struct oval_string_map *objmap,
							struct oval_string_map *sttmap, 
							struct oval_string_map *varmap, 
							struct oval_string_map *sysmap);
static void _oval_result_system_scan_state_for_references(struct oval_syschar_model *syschar_model, 
							struct oval_state *state,
							struct oval_string_map *objmap,
							struct oval_string_map *sttmap, 
							struct oval_string_map *varmap, 
							struct oval_string_map *sysmap);

static void _oval_result_system_scan_component_for_references(struct oval_syschar_model *syschar_model, 
							struct oval_component *component,	
							struct oval_string_map *objmap,
							struct oval_string_map *sttmap, 
							struct oval_string_map *varmap, 
							struct oval_string_map *sysmap);

static bool _oval_result_system_resolve_syschar(struct oval_syschar *syschar, struct oval_string_map *sysmap);





struct oval_result_system *oval_result_system_new(struct oval_results_model *model,
						  struct oval_syschar_model *syschar_model)
{
	__attribute__nonnull__(model);
	oval_result_system_t *sys;

	sys = (oval_result_system_t *) oscap_alloc(sizeof(oval_result_system_t));
	if (sys == NULL)
		return NULL;

	sys->definitions = oval_smc_new();
	sys->tests = oval_smc_new();
	sys->syschar_model = syschar_model;
	sys->model = model;

	oval_results_model_add_system(model, sys);

	return sys;
}

struct oval_result_system *oval_result_system_clone(struct oval_results_model *new_model,
						    struct oval_result_system *old_system)
{
	__attribute__nonnull__(old_system);

	struct oval_result_system *new_system =
	    oval_result_system_new(new_model, oval_result_system_get_syschar_model(old_system));

	oval_smc_free0(new_system->definitions);
	oval_smc_free0(new_system->tests);
	new_system->definitions = oval_smc_clone_user(old_system->definitions, (oval_smc_user_clone_func) oval_result_definition_clone, new_system);
	new_system->tests = oval_smc_clone_user(old_system->tests, (oval_smc_user_clone_func) oval_result_test_clone, new_system);

	return new_system;
}

void oval_result_system_free(struct oval_result_system *sys)
{
{'fraction_non_alphanumeric': 0.07674850422942026, 'fraction_numerical': 0.005260986177016712, 'mean_word_length': 4.757125890736342, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4711898', 'n_tokens_mistral': 3658, 'n_tokens_neox': 3129, 'n_words': 787}