aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatheus Afonso Martins Moreira <matheus.a.m.moreira@gmail.com>2020-01-02 05:28:25 -0300
committerMauro Carvalho Chehab <mchehab+huawei@kernel.org>2020-03-13 10:49:04 +0100
commit13eece07b52361b2a3273ef4243c5d4e3ce7881e (patch)
tree3e32bbea6f4ef14f6dbdb4990222d766db2a72cb
parent0c6eefa72ccebed094c272e2b115df4c79816338 (diff)
test: verify types of data sent over D-Bus
Currently, only the dictionary keys are validated. Dictionary values are variant and could benefit from type checking now that types other than string are being used.
-rw-r--r--test/test_dbus.c52
1 files changed, 34 insertions, 18 deletions
diff --git a/test/test_dbus.c b/test/test_dbus.c
index a1af111..4669c9c 100644
--- a/test/test_dbus.c
+++ b/test/test_dbus.c
@@ -156,27 +156,43 @@ int main(int argc, char *argv[])
while (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_INVALID) {
dbus_message_iter_recurse(&entry, &dict);
if (DBUS_TYPE_STRING != dbus_message_iter_get_arg_type(&dict)) {
- fprintf(stderr, "Dict Entry is not string!\n");
+ fprintf(stderr, "Dict Entry key is not string!\n");
} else {
dbus_message_iter_get_basic(&dict, &property);
- if (strcmp(property, ZBAR_SIGNAL_TYPE) == 0) {
- dbus_message_iter_next(&dict);
+ dbus_message_iter_next(&dict);
+ if (DBUS_TYPE_VARIANT != dbus_message_iter_get_arg_type(&dict)) {
+ fprintf(stderr, "Dict Entry value is not variant!\n");
+ } else {
dbus_message_iter_recurse(&dict, &val);
- dbus_message_iter_get_basic(&val, &str);
- fprintf(stderr, "Type = %s\n", str);
- } else if (strcmp(property, ZBAR_SIGNAL_DATA) == 0) {
- dbus_message_iter_next(&dict);
- dbus_message_iter_recurse(&dict, &val);
- dbus_message_iter_get_basic(&val, &str);
- fprintf(stderr, "Value = %s\n", str);
- fprintf(log, "%s\n", str);
- } else if (strcmp(property, ZBAR_SIGNAL_BINARY_DATA) == 0) {
- dbus_message_iter_next(&dict);
- dbus_message_iter_recurse(&dict, &val);
- dbus_message_iter_recurse(&val, &val);
- dbus_message_iter_get_fixed_array(&val, &str, &length);
- fprintf(stderr, "BinaryData[%d]\n", length);
- fwrite(str, sizeof(*str), length, bin_log);
+ if (strcmp(property, ZBAR_SIGNAL_TYPE) == 0) {
+ if (DBUS_TYPE_STRING != dbus_message_iter_get_arg_type(&val)) {
+ fprintf(stderr, "Dict Entry value for barcode type is not string!\n");
+ } else {
+ dbus_message_iter_get_basic(&val, &str);
+ fprintf(stderr, "Type = %s\n", str);
+ }
+ } else if (strcmp(property, ZBAR_SIGNAL_DATA) == 0) {
+ if (DBUS_TYPE_STRING != dbus_message_iter_get_arg_type(&val)) {
+ fprintf(stderr, "Dict Entry value for barcode text data is not string!\n");
+ } else {
+ dbus_message_iter_get_basic(&val, &str);
+ fprintf(stderr, "Value = %s\n", str);
+ fprintf(log, "%s\n", str);
+ }
+ } else if (strcmp(property, ZBAR_SIGNAL_BINARY_DATA) == 0) {
+ if (DBUS_TYPE_ARRAY != dbus_message_iter_get_arg_type(&val)) {
+ fprintf(stderr, "Dict Entry value for barcode binary data is not array!\n");
+ } else {
+ dbus_message_iter_recurse(&val, &val);
+ if (DBUS_TYPE_BYTE != dbus_message_iter_get_arg_type(&val)) {
+ fprintf(stderr, "Dict Entry value for barcode binary data is not array of bytes!\n");
+ } else {
+ dbus_message_iter_get_fixed_array(&val, &str, &length);
+ fprintf(stderr, "BinaryData[%d]\n", length);
+ fwrite(str, sizeof(*str), length, bin_log);
+ }
+ }
+ }
}
}
dbus_message_iter_next(&entry);

Privacy Policy