71
71
*/
72
72
#define CPE_MAX_CHUNK_SIZE 10000
73
73
74
+ /**
75
+ * @brief Query size for affected products updates.
76
+ */
77
+ static int affected_products_query_size = AFFECTED_PRODUCTS_QUERY_SIZE_DEFAULT ;
78
+
74
79
/**
75
80
* @brief Commit size for updates.
76
81
*/
@@ -4055,6 +4060,24 @@ update_scap_cves ()
4055
4060
return 0 ;
4056
4061
}
4057
4062
4063
+ static void
4064
+ exec_affected_products_sql (const char * cve_ids_str )
4065
+ {
4066
+ sql ("INSERT INTO scap2.affected_products"
4067
+ " SELECT DISTINCT scap2.cpe_match_nodes.cve_id, scap2.cpes.id"
4068
+ " FROM scap2.cpe_match_nodes, scap2.cpe_nodes_match_criteria,"
4069
+ " scap2.cpe_matches, scap2.cpes"
4070
+ " WHERE scap2.cpe_match_nodes.cve_id IN (%s)"
4071
+ " AND scap2.cpe_match_nodes.id ="
4072
+ " scap2.cpe_nodes_match_criteria.node_id"
4073
+ " AND scap2.cpe_nodes_match_criteria.vulnerable = 1"
4074
+ " AND scap2.cpe_nodes_match_criteria.match_criteria_id ="
4075
+ " scap2.cpe_matches.match_criteria_id"
4076
+ " AND scap2.cpe_matches.cpe_name_id = scap2.cpes.cpe_name_id"
4077
+ " ON CONFLICT DO NOTHING;" ,
4078
+ cve_ids_str );
4079
+ }
4080
+
4058
4081
/**
4059
4082
* @brief Update SCAP affected products.
4060
4083
*
@@ -4063,17 +4086,40 @@ update_scap_cves ()
4063
4086
static void
4064
4087
update_scap_affected_products ()
4065
4088
{
4089
+ iterator_t cves_iter ;
4090
+ GString * cve_ids_buffer ;
4066
4091
g_info ("Updating affected products" );
4067
4092
4068
- sql ("INSERT INTO scap2.affected_products"
4069
- " SELECT DISTINCT scap2.cpe_match_nodes.cve_id, scap2.cpes.id"
4070
- " FROM scap2.cpe_match_nodes, scap2.cpe_nodes_match_criteria,"
4071
- " scap2.cpe_matches, scap2.cpes"
4072
- " WHERE scap2.cpe_match_nodes.id = scap2.cpe_nodes_match_criteria.node_id"
4073
- " AND scap2.cpe_nodes_match_criteria.vulnerable = 1"
4074
- " AND scap2.cpe_nodes_match_criteria.match_criteria_id ="
4075
- " scap2.cpe_matches.match_criteria_id"
4076
- " AND scap2.cpe_matches.cpe_name_id = scap2.cpes.cpe_name_id;" );
4093
+ init_iterator (& cves_iter ,
4094
+ "SELECT DISTINCT cve_id FROM scap2.cpe_match_nodes" );
4095
+
4096
+ int count = 0 ;
4097
+
4098
+ cve_ids_buffer = g_string_new ("" );
4099
+ while (next (& cves_iter ))
4100
+ {
4101
+ resource_t cve_id ;
4102
+ cve_id = iterator_int64 (& cves_iter , 0 );
4103
+ g_string_append_printf (cve_ids_buffer , "%s%llu" ,
4104
+ cve_ids_buffer -> len ? ", " : "" ,
4105
+ cve_id );
4106
+ count ++ ;
4107
+
4108
+ if (count % affected_products_query_size == 0 )
4109
+ {
4110
+ exec_affected_products_sql (cve_ids_buffer -> str );
4111
+ g_string_truncate (cve_ids_buffer , 0 );
4112
+ g_message ("%s: Products of %d CVEs processed" , __func__ , count );
4113
+ }
4114
+ }
4115
+
4116
+ if (cve_ids_buffer -> len )
4117
+ {
4118
+ exec_affected_products_sql (cve_ids_buffer -> str );
4119
+ g_string_truncate (cve_ids_buffer , 0 );
4120
+ g_message ("%s: Products of %d CVEs processed" , __func__ , count );
4121
+ }
4122
+
4077
4123
}
4078
4124
4079
4125
/**
@@ -5785,6 +5831,20 @@ manage_rebuild_scap (GSList *log_config, const db_conn_info_t *database)
5785
5831
return -1 ;
5786
5832
}
5787
5833
5834
+ /**
5835
+ * @brief Set the affected products query size.
5836
+ *
5837
+ * @param new_size The new affected products query size.
5838
+ */
5839
+ void
5840
+ set_affected_products_query_size (int new_size )
5841
+ {
5842
+ if (new_size <= 0 )
5843
+ affected_products_query_size = AFFECTED_PRODUCTS_QUERY_SIZE_DEFAULT ;
5844
+ else
5845
+ secinfo_commit_size = new_size ;
5846
+ }
5847
+
5788
5848
/**
5789
5849
* @brief Set the SecInfo update commit size.
5790
5850
*
0 commit comments