From e1a4855e09932c2b6dd79a83bf6e87fba33aa519 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Tue, 25 Oct 2022 14:49:38 +0200 Subject: 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 --- build-aux/qmi-codegen/VariableString.py | 5 ++--- 1 file 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' -- cgit v1.2.1