Skip to content

Commit f651a46

Browse files
committed
[fix] Properly handle license abbrevs that match SPDX and legacy
Some legacy license abbreviations match SPDX abbreviations. In these cases, do not assume the license expression is SPDX unless the other tokens are SPDX tokens. This happens in a handful of cases with license abbreviations like "Zlib" or "MIT" and maybe a few others. Fixes: rpminspect#1378 Signed-off-by: David Cantrell <[email protected]>
1 parent 2a2b2a8 commit f651a46

File tree

7 files changed

+1804
-1724
lines changed

7 files changed

+1804
-1724
lines changed

data/remedy/generic.toml

+6
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ case-insensitive. It is only the boolean terms that must be in all
5252
capital letters.
5353
"""
5454

55+
mixed_license_tags = """
56+
The License tag contains mixed used of SPDX and legacy license
57+
identifiers. You must use either all SPDX license identifiers or all
58+
legacy license identifiers; you cannot mix the two systems.
59+
"""
60+
5561
elf_textrel = """
5662
Ensure all object files are compiled with -fPIC.
5763
"""

include/remedy.h

+1
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ extern "C"
100100
#define REMEDY_VENDOR 84
101101
#define REMEDY_VIRUS 85
102102
#define REMEDY_XML 86
103+
#define REMEDY_MIXED_LICENSE_TAGS 87
103104

104105
/* Initialize default remedy strings */
105106
void init_remedy_strings(void);

lib/inspect_license.c

+26-2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
/* Globals */
3030
static const char *srpm = NULL;
3131
static int nspdx = 0;
32+
static int nlegacy = 0;
33+
static int ndual = 0;
3234
string_list_t *booleans = NULL;
3335

3436
/* Local helper functions */
@@ -168,13 +170,20 @@ static bool lic_cb(const char *license_name, void *cb_data)
168170
if (!approved) {
169171
/* invalid - do nothing */
170172
goto done;
173+
}
174+
175+
if (spdx_abbrev && !strcasecmp(lic, spdx_abbrev) && list_contains(fedora_abbrev, lic)) {
176+
/* license token is valid under the legacy system and SPDX */
177+
data->valid = true;
178+
ndual++;
171179
} else if (spdx_abbrev && !strcasecmp(lic, spdx_abbrev)) {
172180
/* SPDX identifier matched */
173181
data->valid = true;
174182
nspdx++;
175183
} else if (list_contains(fedora_abbrev, lic) || (list_len(fedora_abbrev) == 0 && spdx_abbrev == NULL && list_contains(fedora_name, lic))) {
176184
/* Old Fedora abbreviation matches -or- there are no Fedora abbreviations but a Fedora name matches */
177185
data->valid = true;
186+
nlegacy++;
178187
}
179188

180189
done:
@@ -544,21 +553,36 @@ static bool is_valid_license(struct rpminspect *ri, struct result_params *params
544553
free(wlicense);
545554

546555
/* for SPDX tags found, ensure booleans are all uppercase */
547-
if (nspdx > 0 && (booleans && !TAILQ_EMPTY(booleans))) {
556+
if (nlegacy == 0 && ndual == 0 && nspdx > 0 && (booleans && !TAILQ_EMPTY(booleans))) {
548557
TAILQ_FOREACH(entry, booleans, items) {
549558
if ((!strcasecmp(entry->data, "AND") && strcmp(entry->data, "AND"))
550559
|| (!strcasecmp(entry->data, "OR") && strcmp(entry->data, "OR"))) {
551560
r = false;
552561

553562
params->severity = RESULT_BAD;
554563
params->remedy = get_remedy(REMEDY_INVALID_BOOLEAN);
555-
xasprintf(&params->msg, _("SPDX license expressions in use, but an invalid boolean was found: %s; when using SPDX expression the booleans must be in all caps."), entry->data);
564+
xasprintf(&params->msg, _("SPDX license expressions in use in %s, but an invalid boolean was found: %s; when using SPDX expression the booleans must be in all caps."), nevra, entry->data);
565+
xasprintf(&params->details, _("License: %s"), license);
556566
add_result(ri, params);
557567
free(params->msg);
568+
free(params->details);
569+
params->details = NULL;
558570
}
559571
}
560572
}
561573

574+
/* mixed SPDX and legacy tags are forbidden */
575+
if (nlegacy > 0 && nspdx > 0 && ndual == 0) {
576+
params->severity = RESULT_BAD;
577+
params->remedy = get_remedy(REMEDY_MIXED_LICENSE_TAGS);
578+
xasprintf(&params->msg, _("Mixed SPDX and legacy license identifiers found in %s."), nevra);
579+
xasprintf(&params->details, _("License: %s"), license);
580+
add_result(ri, params);
581+
free(params->msg);
582+
free(params->details);
583+
params->details = NULL;
584+
}
585+
562586
return r;
563587
}
564588

lib/remedy.c

+2
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ struct remedy remedies[] = {
102102
{ REMEDY_VENDOR, "vendor", NULL },
103103
{ REMEDY_VIRUS, "virus", NULL },
104104
{ REMEDY_XML, "xml", NULL },
105+
{ REMEDY_MIXED_LICENSE_TAGS, "mixed_license_tags", NULL },
105106
{ 0, NULL, NULL }
106107
};
107108

@@ -196,6 +197,7 @@ void init_remedy_strings(void)
196197
remedies[REMEDY_VENDOR].remedy = _("Change the string specified on the 'Vendor:' line in the spec file.");
197198
remedies[REMEDY_VIRUS].remedy = _("ClamAV has found a virus in the named file. This may be a false positive, but you should manually inspect the file in question to ensure it is clean. This may be a problem with the ClamAV database or detection. If you are sure the file in question is clean, please file a bug with rpminspect for further help.");
198199
remedies[REMEDY_XML].remedy = _("Correct the reported errors in the XML document.");
200+
remedies[REMEDY_MIXED_LICENSE_TAGS].remedy = _("The License tag contains mixed used of SPDX and legacy license identifiers. You must use either all SPDX license identifiers or all legacy license identifiers; you cannot mix the two systems.");
199201

200202
return;
201203
}

po/POTFILES

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
include/compat/queue.h
22
include/constants.h
3+
include/helpers.h
4+
include/i18n.h
35
include/init.h
46
include/inspect.h
57
include/internal/callbacks.h
@@ -8,7 +10,7 @@ include/output.h
810
include/parser.h
911
include/queue.h
1012
include/readelf.h
11-
include/results.h
13+
include/remedy.h
1214
include/rpminspect.h
1315
include/secrules.h
1416
include/types.h
@@ -107,6 +109,7 @@ lib/readelf.c
107109
lib/readfile.c
108110
lib/rebase.c
109111
lib/release.c
112+
lib/remedy.c
110113
lib/results.c
111114
lib/rmtree.c
112115
lib/rpm.c

0 commit comments

Comments
 (0)