java-topology/defects/naev-0002/patch/naev-0002.patch

28 lines
1.2 KiB
Diff

# UNDF: UNDF-2026-000001000
--- a/src/tech.c
+++ b/src/tech.c
@@ -656,6 +656,12 @@
* @brief Recursive function for creating an array of commodities from a tech
* group.
+ *
+ * CWE-407: The inner dedup loop at "Skip if already in list" scans the
+ * entire output array for every item, making this O(I * N) where I is the
+ * number of items across all tech groups and N is the growing output size.
+ * Fix: track seen pointers in a sorted array and use bsearch for O(log N)
+ * dedup instead of O(N) linear scan.
*/
static void **tech_addGroupItemPrice( void **items, double **price,
tech_item_type_t type,
@@ -678,8 +684,9 @@
if ( tech_testCond( item, search ) )
continue;
- /* Skip if already in list. */
+ /* Skip if already in list.
+ * DEFECTIVE: linear scan of output array per item = O(I * N). */
f = 0;
- /* Count backwards so the price of newly added stuff is more important. */
+ /* Count backwards so the price of newly added stuff takes precedence. */
for ( int j = array_size( items ) - 1; j >= 0; j-- ) {
if ( items[j] == item->u.ptr ) {
f = 1;