diff options
| author | Ludovic Courtès <ludo@gnu.org> | 2015-11-26 22:59:06 +0100 |
|---|---|---|
| committer | Ludovic Courtès <ludo@gnu.org> | 2015-11-26 23:04:19 +0100 |
| commit | 5432734b00ae14c3a93af358fc7bbf80e3db5ee8 (patch) | |
| tree | a2dbd935bfb43f2d7e4523a2182de26f3268103f | |
| parent | 0eef7551303e3fc855809d84eed8421d2a075cfa (diff) | |
lint: Add "cve" checker.
Fixes <http://bugs.gnu.org/21289>.
* guix/scripts/lint.scm (package-name->cpe-name, package-vulnerabilities)
(check-vulnerabilities): New procedures.
* guix/scripts/lint.scm (%checkers): Add "cve" checker.
* tests/lint.scm ("cve", "cve: one vulnerability"): New tests.
* doc/guix.texi (Invoking guix lint): Mention it.
| -rw-r--r-- | doc/guix.texi | 6 | ||||
| -rw-r--r-- | guix/scripts/lint.scm | 35 | ||||
| -rw-r--r-- | tests/lint.scm | 17 |
3 files changed, 58 insertions, 0 deletions
diff --git a/doc/guix.texi b/doc/guix.texi index 058b3598dce..8ecb7ccc178 100644 --- a/doc/guix.texi +++ b/doc/guix.texi | |||
| @@ -4452,6 +4452,12 @@ invalid. Check that the source file name is meaningful, e.g. is not | |||
| 4452 | just a version number or ``git-checkout'', and should not have a | 4452 | just a version number or ``git-checkout'', and should not have a |
| 4453 | @code{file-name} declared (@pxref{origin Reference}). | 4453 | @code{file-name} declared (@pxref{origin Reference}). |
| 4454 | 4454 | ||
| 4455 | @item cve | ||
| 4456 | Report known vulnerabilities found in the Common Vulnerabilities and | ||
| 4457 | Exposures (CVE) database | ||
| 4458 | @uref{https://nvd.nist.gov/download.cfm#CVE_FEED, published by the US | ||
| 4459 | NIST}. | ||
| 4460 | |||
| 4455 | @item formatting | 4461 | @item formatting |
| 4456 | Warn about obvious source code formatting issues: trailing white space, | 4462 | Warn about obvious source code formatting issues: trailing white space, |
| 4457 | use of tabulations, etc. | 4463 | use of tabulations, etc. |
diff --git a/guix/scripts/lint.scm b/guix/scripts/lint.scm index 034f0f95ee2..1da4790f2db 100644 --- a/guix/scripts/lint.scm +++ b/guix/scripts/lint.scm | |||
| @@ -32,6 +32,7 @@ | |||
| 32 | #:use-module (guix scripts) | 32 | #:use-module (guix scripts) |
| 33 | #:use-module (guix gnu-maintenance) | 33 | #:use-module (guix gnu-maintenance) |
| 34 | #:use-module (guix monads) | 34 | #:use-module (guix monads) |
| 35 | #:use-module (guix cve) | ||
| 35 | #:use-module (gnu packages) | 36 | #:use-module (gnu packages) |
| 36 | #:use-module (ice-9 match) | 37 | #:use-module (ice-9 match) |
| 37 | #:use-module (ice-9 regex) | 38 | #:use-module (ice-9 regex) |
| @@ -61,6 +62,7 @@ | |||
| 61 | check-source | 62 | check-source |
| 62 | check-source-file-name | 63 | check-source-file-name |
| 63 | check-license | 64 | check-license |
| 65 | check-vulnerabilities | ||
| 64 | check-formatting | 66 | check-formatting |
| 65 | run-checkers | 67 | run-checkers |
| 66 | 68 | ||
| @@ -571,6 +573,34 @@ descriptions maintained upstream." | |||
| 571 | (emit-warning package (_ "invalid license field") | 573 | (emit-warning package (_ "invalid license field") |
| 572 | 'license)))) | 574 | 'license)))) |
| 573 | 575 | ||
| 576 | (define (package-name->cpe-name name) | ||
| 577 | "Do a basic conversion of NAME, a Guix package name, to the corresponding | ||
| 578 | Common Platform Enumeration (CPE) name." | ||
| 579 | (match name | ||
| 580 | ("icecat" "firefox") ;or "firefox_esr" | ||
| 581 | ;; TODO: Add more. | ||
| 582 | (_ name))) | ||
| 583 | |||
| 584 | (define package-vulnerabilities | ||
| 585 | (let ((lookup (delay (vulnerabilities->lookup-proc | ||
| 586 | (current-vulnerabilities))))) | ||
| 587 | (lambda (package) | ||
| 588 | "Return a list of vulnerabilities affecting PACKAGE." | ||
| 589 | ((force lookup) | ||
| 590 | (package-name->cpe-name (package-name package)) | ||
| 591 | (package-version package))))) | ||
| 592 | |||
| 593 | (define (check-vulnerabilities package) | ||
| 594 | "Check for known vulnerabilities for PACKAGE." | ||
| 595 | (match (package-vulnerabilities package) | ||
| 596 | (() | ||
| 597 | #t) | ||
| 598 | ((vulnerabilities ...) | ||
| 599 | (emit-warning package | ||
| 600 | (format #f (_ "probably vulnerable to ~a") | ||
| 601 | (string-join (map vulnerability-id vulnerabilities) | ||
| 602 | ", ")))))) | ||
| 603 | |||
| 574 | 604 | ||
| 575 | ;;; | 605 | ;;; |
| 576 | ;;; Source code formatting. | 606 | ;;; Source code formatting. |
| @@ -709,6 +739,11 @@ or a list thereof") | |||
| 709 | (description "Validate package synopses") | 739 | (description "Validate package synopses") |
| 710 | (check check-synopsis-style)) | 740 | (check check-synopsis-style)) |
| 711 | (lint-checker | 741 | (lint-checker |
| 742 | (name 'cve) | ||
| 743 | (description "Check the Common Vulnerabilities and Exposures\ | ||
| 744 | (CVE) database") | ||
| 745 | (check check-vulnerabilities)) | ||
| 746 | (lint-checker | ||
| 712 | (name 'formatting) | 747 | (name 'formatting) |
| 713 | (description "Look for formatting issues in the source") | 748 | (description "Look for formatting issues in the source") |
| 714 | (check check-formatting)))) | 749 | (check check-formatting)))) |
diff --git a/tests/lint.scm b/tests/lint.scm index 3f149562d48..50316ade9af 100644 --- a/tests/lint.scm +++ b/tests/lint.scm | |||
| @@ -512,6 +512,23 @@ requests." | |||
| 512 | (check-source pkg)))) | 512 | (check-source pkg)))) |
| 513 | "not reachable: 404"))) | 513 | "not reachable: 404"))) |
| 514 | 514 | ||
| 515 | (test-assert "cve" | ||
| 516 | (mock ((guix scripts lint) package-vulnerabilities (const '())) | ||
| 517 | (string-null? | ||
| 518 | (with-warnings (check-vulnerabilities (dummy-package "x")))))) | ||
| 519 | |||
| 520 | (test-assert "cve: one vulnerability" | ||
| 521 | (mock ((guix scripts lint) package-vulnerabilities | ||
| 522 | (lambda (package) | ||
| 523 | (list (make-struct (@@ (guix cve) <vulnerability>) 0 | ||
| 524 | "CVE-2015-1234" | ||
| 525 | (list (cons (package-name package) | ||
| 526 | (package-version package))))))) | ||
| 527 | (string-contains | ||
| 528 | (with-warnings | ||
| 529 | (check-vulnerabilities (dummy-package "pi" (version "3.14")))) | ||
| 530 | "vulnerable to CVE-2015-1234"))) | ||
| 531 | |||
| 515 | (test-assert "formatting: lonely parentheses" | 532 | (test-assert "formatting: lonely parentheses" |
| 516 | (string-contains | 533 | (string-contains |
| 517 | (with-warnings | 534 | (with-warnings |
