Skip to content

Commit 87036c7

Browse files
mscasso-scanosscore software devel
andauthored
5.4.12 (#88)
* fix memory issue with version md5 calculation * improve final selection logic * increase version --------- Co-authored-by: core software devel <[email protected]>
1 parent 2bd17d4 commit 87036c7

File tree

4 files changed

+32
-28
lines changed

4 files changed

+32
-28
lines changed

inc/scanoss.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
#define WFP_REC_LN 18
4141

4242
/* Log files */
43-
#define SCANOSS_VERSION "5.4.11"
43+
#define SCANOSS_VERSION "5.4.12"
4444
#define SCAN_LOG "/tmp/scanoss_scan.log"
4545
#define MAP_DUMP "/tmp/scanoss_map.dump"
4646
#define SLOW_QUERY_LOG "/tmp/scanoss_slow_query.log"

src/match.c

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -640,11 +640,17 @@ void match_select_best(scan_data_t *scan)
640640

641641
LIST_FOREACH(item, &scan->matches_list_array[i]->headp, entries)
642642
{
643-
if (!item->match->component_list.headp.lh_first)
643+
match_data_t * match = item->match;
644+
645+
if (!match->component_list.headp.lh_first)
644646
continue;
647+
component_data_t * match_component = match->component_list.headp.lh_first->component;
648+
649+
scanlog("%s\n",match_component->purls[0]);
650+
651+
match_data_t * best_match = scan->matches_list_array[i]->best_match;
652+
component_data_t * best_match_component = best_match->component_list.headp.lh_first->component;
645653

646-
component_data_t * best_match_component = scan->matches_list_array[i]->best_match->component_list.headp.lh_first->component;
647-
component_data_t * match_component = item->match->component_list.headp.lh_first->component;
648654
if (path_is_third_party(match_component->file))
649655
continue;
650656

@@ -653,34 +659,32 @@ void match_select_best(scan_data_t *scan)
653659
best_match_component->release_date,
654660
scan->matches_list_array[i]->best_match->hits,
655661
match_component->purls[0], match_component->release_date, item->match->hits);
656-
657-
if (!strcmp(best_match_component->purls[0],match_component->purls[0]))
658-
{
659-
if (abs(scan->matches_list_array[i]->best_match->hits - item->match->hits) <= 2 &&
660-
find_oldest_match(scan->matches_list_array[i]->best_match, item->match))
661-
{
662-
scanlog("Replacing best match for an older version with equal hits\n");
663-
scan->matches_list_array[i]->best_match = item->match;
664-
}
665-
else if (scan->matches_list_array[i]->best_match->hits + 1 < item->match->hits)
666-
{
667-
scanlog("Replacing best match for a newers version with more hits\n");
668-
scan->matches_list_array[i]->best_match = item->match;
669-
}
670-
671-
}
672-
else if (scan->matches_list_array[i]->best_match->hits > item->match->hits)
673-
{
674-
scanlog("Hits are lower than the best match, no more comparations are needed. Exiting...\n");
675-
break;
676-
}
677662

663+
//If the best match is not good or is not identified be prefer the candidate.
678664
if ((!best_match_component->identified && match_component->identified) ||
679-
(strcmp(best_match_component->vendor,best_match_component->component) && !strcmp(match_component->vendor, match_component->component)) ||
680665
(path_is_third_party(best_match_component->file)))
681666
{
682667
scanlog("Replacing best match for a prefered component\n");
683668
scan->matches_list_array[i]->best_match = item->match;
669+
continue;
670+
}
671+
672+
//If best match has 20% more of hits do nothing.
673+
if (best_match->hits >= match->hits * 1.2)
674+
continue;
675+
676+
//if cantidate has 10% more of hits do not consider dates and switch
677+
if (match->hits > best_match->hits * 1.1)
678+
{
679+
scanlog("Replacing best match due to big hits difference\n");
680+
scan->matches_list_array[i]->best_match = item->match;
681+
}
682+
// if the hit numbers are close, select the oldest.
683+
else if (abs(scan->matches_list_array[i]->best_match->hits - item->match->hits) <= 2 &&
684+
find_oldest_match(scan->matches_list_array[i]->best_match, item->match))
685+
{
686+
scanlog("Replacing best match for an older version with equal hits\n");
687+
scan->matches_list_array[i]->best_match = item->match;
684688
}
685689
}
686690
}

src/parse.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ component_item *get_components(char *filepath)
237237
exit(EXIT_FAILURE);
238238
}
239239

240-
component_item *out = calloc(MAX_SBOM_ITEMS * sizeof(component_item), 1);
240+
component_item *out = calloc((MAX_SBOM_ITEMS+10) * sizeof(component_item), 1);
241241
int component_index = -1;
242242
work_json_value(&component_index, value, 0, out);
243243

src/vulnerability.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ static bool print_vulnerability_item(uint8_t *key, uint8_t *subkey, int subkey_l
242242
*/
243243
void version_md5(uint8_t *out, char *vendor, char *component, char *version)
244244
{
245-
char triplet[strlen(vendor) + strlen(vendor) + strlen(component) + 10];
245+
char triplet[strlen(vendor) + strlen(version) + strlen(component) + 10];
246246
sprintf(triplet, "%s/%s/%s", vendor, component, version);
247247
MD5((uint8_t *)triplet, strlen(triplet), out);
248248
}

0 commit comments

Comments
 (0)