diff options
author | Aleksander Morgado <aleksander@lanedo.com> | 2012-10-30 15:08:02 +0100 |
---|---|---|
committer | Aleksander Morgado <aleksander@lanedo.com> | 2012-10-30 20:42:59 +0100 |
commit | 4c98ff41cca3c83498c8f8b6f502fa56e4e31653 (patch) | |
tree | 7935c2d8132809eeb74c7cd655d9f87b560f8db3 /build-aux/qmi-codegen/FieldResult.py | |
parent | 7cce18820ef2142781c334d20e162d814695a409 (diff) | |
download | external_libqmi-4c98ff41cca3c83498c8f8b6f502fa56e4e31653.zip external_libqmi-4c98ff41cca3c83498c8f8b6f502fa56e4e31653.tar.gz external_libqmi-4c98ff41cca3c83498c8f8b6f502fa56e4e31653.tar.bz2 |
qmi-codegen: validate TLV before really reading it
Try to handle buggy firmware, or just make the library more robust, by
validating the read TLV before really reading it. If a TLV is not considered
valid, we just skip it for now.
E.g.: the "Detailed Service Status" TLV (0x21) in the "NAS Get Serving System"
message is supposed to be a sequence of 5 bytes, but some models (e.g. ZTE MF683)
end up sending only the first 4 bytes.
Diffstat (limited to 'build-aux/qmi-codegen/FieldResult.py')
-rw-r--r-- | build-aux/qmi-codegen/FieldResult.py | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/build-aux/qmi-codegen/FieldResult.py b/build-aux/qmi-codegen/FieldResult.py index cc298ee..6b7b91e 100644 --- a/build-aux/qmi-codegen/FieldResult.py +++ b/build-aux/qmi-codegen/FieldResult.py @@ -107,15 +107,35 @@ class FieldResult(Field): Emit the method responsible for getting a printable representation of this TLV field. """ - def emit_tlv_get_printable(self, f): - if TypeFactory.is_get_printable_emitted(self.fullname): + def emit_tlv_helpers(self, f): + if TypeFactory.helpers_emitted(self.fullname): return - TypeFactory.set_get_printable_emitted(self.fullname) + TypeFactory.set_helpers_emitted(self.fullname) translations = { 'name' : self.name, 'tlv_id' : self.id_enum_name, 'underscore' : utils.build_underscore_name (self.fullname) } + + template = ( + '\n' + 'static gboolean\n' + '${underscore}_validate (\n' + ' const guint8 *buffer,\n' + ' guint16 buffer_len)\n' + '{\n' + ' static const guint expected_len = 4;\n' + '\n' + ' if (buffer_len < expected_len) {\n' + ' g_warning ("Cannot read the \'${name}\' TLV: expected \'%u\' bytes, but only got \'%u\' bytes",\n' + ' expected_len, buffer_len);\n' + ' return FALSE;\n' + ' }\n' + '\n' + ' return TRUE;\n' + '}\n') + f.write(string.Template(template).substitute(translations)) + template = ( '\n' 'static gchar *\n' |