@@ -21,8 +21,10 @@ import (
21
21
type CveInfo interface {
22
22
GetImageListForCVE (ctx context.Context , repo , cveID string ) ([]cvemodel.TagInfo , error )
23
23
GetImageListWithCVEFixed (ctx context.Context , repo , cveID string ) ([]cvemodel.TagInfo , error )
24
- GetCVEListForImage (ctx context.Context , repo , tag string , searchedCVE string , excludedCVE string ,
24
+ GetCVEListForImage (ctx context.Context , repo , tag string , searchedCVE , excludedCVE string ,
25
25
pageinput cvemodel.PageInput ) ([]cvemodel.CVE , cvemodel.ImageCVESummary , zcommon.PageInfo , error )
26
+ GetCVEDiffListForImages (ctx context.Context , minuend , subtrahend , searchedCVE , excludedCVE string ,
27
+ pageInput cvemodel.PageInput ) ([]cvemodel.CVE , cvemodel.ImageCVESummary , zcommon.PageInfo , error )
26
28
GetCVESummaryForImageMedia (ctx context.Context , repo , digestStr , mediaType string ) (cvemodel.ImageCVESummary , error )
27
29
}
28
30
@@ -329,7 +331,21 @@ func getConfigAndDigest(metaDB mTypes.MetaDB, manifestDigestStr string) (ispec.I
329
331
return manifestData .Manifests [0 ].Config , manifestDigest , err
330
332
}
331
333
332
- func filterCVEList (cveMap map [string ]cvemodel.CVE , searchedCVE , excludedCVE string , pageFinder * CvePageFinder ) {
334
+ func filterCVEMap (cveMap map [string ]cvemodel.CVE , searchedCVE , excludedCVE string , pageFinder * CvePageFinder ) {
335
+ searchedCVE = strings .ToUpper (searchedCVE )
336
+
337
+ for _ , cve := range cveMap {
338
+ if excludedCVE != "" && cve .ContainsStr (excludedCVE ) {
339
+ continue
340
+ }
341
+
342
+ if cve .ContainsStr (searchedCVE ) {
343
+ pageFinder .Add (cve )
344
+ }
345
+ }
346
+ }
347
+
348
+ func filterCVEList (cveMap []cvemodel.CVE , searchedCVE , excludedCVE string , pageFinder * CvePageFinder ) {
333
349
searchedCVE = strings .ToUpper (searchedCVE )
334
350
335
351
for _ , cve := range cveMap {
@@ -373,13 +389,98 @@ func (cveinfo BaseCveInfo) GetCVEListForImage(ctx context.Context, repo, ref str
373
389
return []cvemodel.CVE {}, imageCVESummary , zcommon.PageInfo {}, err
374
390
}
375
391
376
- filterCVEList (cveMap , searchedCVE , excludedCVE , pageFinder )
392
+ filterCVEMap (cveMap , searchedCVE , excludedCVE , pageFinder )
377
393
378
394
cveList , pageInfo := pageFinder .Page ()
379
395
380
396
return cveList , imageCVESummary , pageInfo , nil
381
397
}
382
398
399
+ func (cveinfo BaseCveInfo ) GetCVEDiffListForImages (ctx context.Context , minuend , subtrahend , searchedCVE string ,
400
+ excludedCVE string , pageInput cvemodel.PageInput ,
401
+ ) ([]cvemodel.CVE , cvemodel.ImageCVESummary , zcommon.PageInfo , error ) {
402
+ minuendRepo , minuendRef , _ := zcommon .GetImageDirAndReference (minuend )
403
+ subtrahendRepo , subtrahendRef , _ := zcommon .GetImageDirAndReference (subtrahend )
404
+
405
+ // get the CVEs of image and comparedImage
406
+ minuendCVEList , _ , _ , err := cveinfo .GetCVEListForImage (ctx , minuendRepo , minuendRef , searchedCVE , excludedCVE ,
407
+ cvemodel.PageInput {})
408
+ if err != nil {
409
+ return nil , cvemodel.ImageCVESummary {}, zcommon.PageInfo {}, err
410
+ }
411
+
412
+ subtrahendCVEList , _ , _ , err := cveinfo .GetCVEListForImage (ctx , subtrahendRepo , subtrahendRef ,
413
+ searchedCVE , excludedCVE , cvemodel.PageInput {})
414
+ if err != nil {
415
+ return nil , cvemodel.ImageCVESummary {}, zcommon.PageInfo {}, err
416
+ }
417
+
418
+ subtrahendCVEMap := map [string ]cvemodel.CVE {}
419
+
420
+ for _ , cve := range subtrahendCVEList {
421
+ cve := cve
422
+ subtrahendCVEMap [cve .ID ] = cve
423
+ }
424
+
425
+ var (
426
+ count int
427
+ unknownCount int
428
+ lowCount int
429
+ mediumCount int
430
+ highCount int
431
+ criticalCount int
432
+ maxSeverity string
433
+
434
+ diffCVEs = []cvemodel.CVE {}
435
+ )
436
+
437
+ for i := range minuendCVEList {
438
+ if _ , ok := subtrahendCVEMap [minuendCVEList [i ].ID ]; ! ok {
439
+ diffCVEs = append (diffCVEs , minuendCVEList [i ])
440
+
441
+ switch minuendCVEList [i ].Severity {
442
+ case cvemodel .SeverityUnknown :
443
+ unknownCount ++
444
+ case cvemodel .SeverityLow :
445
+ lowCount ++
446
+ case cvemodel .SeverityMedium :
447
+ mediumCount ++
448
+ case cvemodel .SeverityHigh :
449
+ highCount ++
450
+ case cvemodel .SeverityCritical :
451
+ criticalCount ++
452
+ }
453
+
454
+ if cvemodel .CompareSeverities (maxSeverity , minuendCVEList [i ].Severity ) > 0 {
455
+ maxSeverity = minuendCVEList [i ].Severity
456
+ }
457
+ }
458
+ }
459
+
460
+ pageFinder , err := NewCvePageFinder (pageInput .Limit , pageInput .Offset , pageInput .SortBy )
461
+ if err != nil {
462
+ return nil , cvemodel.ImageCVESummary {}, zcommon.PageInfo {}, err
463
+ }
464
+
465
+ filterCVEList (diffCVEs , "" , "" , pageFinder )
466
+
467
+ cveList , pageInfo := pageFinder .Page ()
468
+
469
+ count = unknownCount + lowCount + mediumCount + highCount + criticalCount
470
+
471
+ diffCVESummary := cvemodel.ImageCVESummary {
472
+ Count : count ,
473
+ UnknownCount : unknownCount ,
474
+ LowCount : lowCount ,
475
+ MediumCount : mediumCount ,
476
+ HighCount : highCount ,
477
+ CriticalCount : criticalCount ,
478
+ MaxSeverity : maxSeverity ,
479
+ }
480
+
481
+ return cveList , diffCVESummary , pageInfo , nil
482
+ }
483
+
383
484
func (cveinfo BaseCveInfo ) GetCVESummaryForImageMedia (ctx context.Context , repo , digestStr , mediaType string ,
384
485
) (cvemodel.ImageCVESummary , error ) {
385
486
// There are several cases, expected returned values below:
0 commit comments