summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksander Morgado <aleksander@aleksander.es>2022-10-25 14:49:38 +0200
committerAleksander Morgado <aleksander@aleksander.es>2022-10-25 14:55:12 +0200
commite1a4855e09932c2b6dd79a83bf6e87fba33aa519 (patch)
tree6b5ddb19e98e60a62e4862312918af700b618120
parentba5902f8f583a783b5d81ac03f211e742f0fec47 (diff)
downloadlibqmi-e1a4855e09932c2b6dd79a83bf6e87fba33aa519.tar.gz
build-aux,codegen: always fully clear fixed size array
We don't know how many valid bytes will be read in the qmi_message_tlv_read_fixed_size_string() call, so ensure the target array is completely cleared in case we read less than expected. E.g. for a 2 digit MNC field reported in the LTE System Info TLV, we would find a 3 byte array containing the last byte as 0xFF. In this case, the 3rd byte won't be set in the target array as it wouldn't be valid UTF-8. Fixes https://gitlab.freedesktop.org/mobile-broadband/libqmi/-/issues/97
-rw-r--r--build-aux/qmi-codegen/VariableString.py5
1 files changed, 2 insertions, 3 deletions
diff --git a/build-aux/qmi-codegen/VariableString.py b/build-aux/qmi-codegen/VariableString.py
index b0526ab4..53fe2b7c 100644
--- a/build-aux/qmi-codegen/VariableString.py
+++ b/build-aux/qmi-codegen/VariableString.py
@@ -138,11 +138,10 @@ class VariableString(Variable):
template = (
'\n'
'${lp}{\n'
- '${lp} gchar tmp[${fixed_size_plus_one}];\n'
+ '${lp} gchar tmp[${fixed_size_plus_one}] = { \'\\0\' };\n'
'\n'
'${lp} if (!qmi_message_tlv_read_fixed_size_string (message, init_offset, &offset, ${fixed_size}, &tmp[0], &error))\n'
- '${lp} goto out;\n'
- '${lp} tmp[${fixed_size}] = \'\\0\';\n')
+ '${lp} goto out;\n')
else:
translations['n_size_prefix_bytes'] = self.n_size_prefix_bytes
translations['max_size'] = self.max_size if self.max_size != '' else '0'