summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoreb3095 <45504889+eb3095@users.noreply.github.com>2021-03-16 12:35:05 -0400
committerGitHub <noreply@github.com>2021-03-16 11:35:05 -0500
commitf35181fa970453ba6c7c14575b12185533391b97 (patch)
treebe7334c5ffa3fba08357d0499386ef40f14d6ea2
parent3aeb14cd46613b97afefc4632909f6e9b83d0230 (diff)
downloadvyos-cloud-init-f35181fa970453ba6c7c14575b12185533391b97.tar.gz
vyos-cloud-init-f35181fa970453ba6c7c14575b12185533391b97.zip
Fix stack trace if vendordata_raw contained an array (#837)
The implementation in existing datasources means that vendordata_raw is not "raw" as it ideally would be. Instead, actual values may include bytes, string or list. If the value was a list, then the attempt to persist that data to a file in '_store_rawdata' would raise a TypeError. The change is to encode with util.json_dumps (which is safe for binary data) before writing.
-rw-r--r--cloudinit/stages.py18
-rw-r--r--tools/.github-cla-signers1
2 files changed, 15 insertions, 4 deletions
diff --git a/cloudinit/stages.py b/cloudinit/stages.py
index 3ef4491c..5bacc85d 100644
--- a/cloudinit/stages.py
+++ b/cloudinit/stages.py
@@ -364,12 +364,12 @@ class Init(object):
'userdata')
self._store_processeddata(self.datasource.get_userdata(),
'userdata')
- self._store_rawdata(self.datasource.get_vendordata_raw(),
- 'vendordata')
+ self._store_raw_vendordata(self.datasource.get_vendordata_raw(),
+ 'vendordata')
self._store_processeddata(self.datasource.get_vendordata(),
'vendordata')
- self._store_rawdata(self.datasource.get_vendordata2_raw(),
- 'vendordata2')
+ self._store_raw_vendordata(self.datasource.get_vendordata2_raw(),
+ 'vendordata2')
self._store_processeddata(self.datasource.get_vendordata2(),
'vendordata2')
@@ -397,6 +397,16 @@ class Init(object):
data = b''
util.write_file(self._get_ipath('%s_raw' % datasource), data, 0o600)
+ def _store_raw_vendordata(self, data, datasource):
+ # Only these data types
+ if data is not None and type(data) not in [bytes, str, list]:
+ raise TypeError("vendordata_raw is unsupported type '%s'" %
+ str(type(data)))
+ # This data may be a list, convert it to a string if so
+ if isinstance(data, list):
+ data = util.json_dumps(data)
+ self._store_rawdata(data, datasource)
+
def _store_processeddata(self, processed_data, datasource):
# processed is a Mime message, so write as string.
if processed_data is None:
diff --git a/tools/.github-cla-signers b/tools/.github-cla-signers
index aca0ee5e..5c57acac 100644
--- a/tools/.github-cla-signers
+++ b/tools/.github-cla-signers
@@ -14,6 +14,7 @@ dankenigsberg
dermotbradley
dhensby
eandersson
+eb3095
emmanuelthome
izzyleung
johnsonshi