Skip to contentSkip to conversation

create-spdx: Add check for variable contents along with quotes

PATCH Superseded Saul Wold 2 participants 3 messages Feb 16, 2023

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Saul Wold

author
#0 lore raw

PATCH 1/1 create-spdx: Add check for variable contents along with quotes

This adds a check to ensure we that if a variable is empty it gets an empty string, this also adds quotes to indicate the variable contents.

          "comment": "CUSTOM_SPECIAL=''"

or
"comment": "CUSTOM_SPECIAL= 'variable contents'"

---
 meta/classes/create-spdx-2.2.bbclass | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
meta/classes/create-spdx-2.2.bbclass +4 -1
index 28a42e009f6..8b18ada40a4 100644
@@ -484,7 +484,10 @@ python do_create_spdx() {
 
     if d.getVar("SPDX_CUSTOM_ANNOTATION_VARS"):
         for var in d.getVar('SPDX_CUSTOM_ANNOTATION_VARS').split():
-            recipe.annotations.append(create_annotation(d, var + "=" + d.getVar(var)))
+            if d.getVar(var):
+                recipe.annotations.append(create_annotation(d, var + "= '" + d.getVar(var) + "'"))
+            else:
+                recipe.annotations.append(create_annotation(d, var + "=''"))
 
     # Some CVEs may be patched during the build process without incrementing the version number,
     # so querying for CVEs based on the CPE id can lead to false positives. To account for this,
Signature · 1 line
2.25.1
#1 lore raw
Quoted 19 lines · Saul Wold

This adds a check to ensure we that if a variable is empty it gets an empty string, this also adds quotes to indicate the variable contents.

          "comment": "CUSTOM_SPECIAL=''"

or
"comment": "CUSTOM_SPECIAL= 'variable contents'"

---
 meta/classes/create-spdx-2.2.bbclass | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
meta/classes/create-spdx-2.2.bbclass +0 -0
index 28a42e009f6..8b18ada40a4 100644

meta/classes/create-spdx-2.2.bbclass python do_create_spdx() { · line 488

Quoted 6 lines
meta/classes/create-spdx-2.2.bbclass +2 -1
@@ -484,7 +484,10 @@ python do_create_spdx() {
 
     if d.getVar("SPDX_CUSTOM_ANNOTATION_VARS"):
         for var in d.getVar('SPDX_CUSTOM_ANNOTATION_VARS').split():
-            recipe.annotations.append(create_annotation(d, var + "=" + d.getVar(var)))
+            if d.getVar(var):
+                recipe.annotations.append(create_annotation(d, var + "= '" + d.getVar(var) + "'"))

Why the extra space after the = ?

Does the variable need some escaping in case it already has a single quote in it?

Quoted 8 lines
meta/classes/create-spdx-2.2.bbclass +2 -1
+            else:
+                recipe.annotations.append(create_annotation(d, var + "=''"))
 
     # Some CVEs may be patched during the build process without incrementing the version number,
     # so querying for CVEs based on the CPE id can lead to false positives. To account for this,
--

2.25.1

#2 lore raw
Quoted 21 lines · Joshua Watt
Quoted 20 lines · Saul Wold

This adds a check to ensure we that if a variable is empty it gets an empty string, this also adds quotes to indicate the variable contents.

           "comment": "CUSTOM_SPECIAL=''"

or
"comment": "CUSTOM_SPECIAL= 'variable contents'"

---
  meta/classes/create-spdx-2.2.bbclass | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)
meta/classes/create-spdx-2.2.bbclass +0 -0
index 28a42e009f6..8b18ada40a4 100644
@@ -484,7 +484,10 @@ python do_create_spdx() {
 
Quoted 8 lines

meta/classes/create-spdx-2.2.bbclass python do_create_spdx() { · line 488

Quoted 5 lines
meta/classes/create-spdx-2.2.bbclass +2 -1
      if d.getVar("SPDX_CUSTOM_ANNOTATION_VARS"):
          for var in d.getVar('SPDX_CUSTOM_ANNOTATION_VARS').split():
-            recipe.annotations.append(create_annotation(d, var + "=" + d.getVar(var)))
+            if d.getVar(var):
+                recipe.annotations.append(create_annotation(d, var + "= '" + d.getVar(var) + "'"))

Why the extra space after the = ?

Right, probably should remove that.

Quoted 3 lines

Does the variable need some escaping in case it already has a single quote in it?

Was thinking about consistency with the empty case below, but I guess we need to think not just of a "stray" single quote in the string, but also a stray double quote (").

I guess we can just remove the single quotes completely for both cases.

Sau!

Quoted 8 lines
Quoted 8 lines
meta/classes/create-spdx-2.2.bbclass +2 -1
+            else:
+                recipe.annotations.append(create_annotation(d, var + "=''"))
 
      # Some CVEs may be patched during the build process without incrementing the version number,
      # so querying for CVEs based on the CPE id can lead to false positives. To account for this,
--

2.25.1