mirror of
https://git.kernel.org/pub/scm/network/wireless/iwd.git
synced 2024-12-22 21:22:37 +01:00
diagnostics: check dbus variant parsing
If the diagnostics dictionary is invalid print an error and do not continue parsing.
This commit is contained in:
parent
af8438878f
commit
5a65bc37fe
@ -31,7 +31,7 @@
|
|||||||
#include "client/diagnostic.h"
|
#include "client/diagnostic.h"
|
||||||
#include "client/display.h"
|
#include "client/display.h"
|
||||||
|
|
||||||
typedef void (*display_dict_custom_func_t)(struct l_dbus_message_iter *variant,
|
typedef bool (*display_dict_custom_func_t)(struct l_dbus_message_iter *variant,
|
||||||
const char *key, const char *margin,
|
const char *key, const char *margin,
|
||||||
int name_column_width, int value_column_width);
|
int name_column_width, int value_column_width);
|
||||||
|
|
||||||
@ -64,16 +64,19 @@ static const struct diagnostic_dict_mapping *find_mapping(const char *key,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void display_bitrate_100kbps(struct l_dbus_message_iter *variant,
|
static bool display_bitrate_100kbps(struct l_dbus_message_iter *variant,
|
||||||
const char *key, const char *margin,
|
const char *key, const char *margin,
|
||||||
int name_column_width, int value_column_width)
|
int name_column_width, int value_column_width)
|
||||||
{
|
{
|
||||||
uint32_t rate;
|
uint32_t rate;
|
||||||
|
|
||||||
l_dbus_message_iter_get_variant(variant, "u", &rate);
|
if (!l_dbus_message_iter_get_variant(variant, "u", &rate))
|
||||||
|
return false;
|
||||||
|
|
||||||
display("%s%-*s%-*u Kbit/s\n", margin, name_column_width, key,
|
display("%s%-*s%-*u Kbit/s\n", margin, name_column_width, key,
|
||||||
value_column_width, rate * 100);
|
value_column_width, rate * 100);
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct diagnostic_dict_mapping diagnostic_mapping[] = {
|
static const struct diagnostic_dict_mapping diagnostic_mapping[] = {
|
||||||
@ -115,39 +118,48 @@ void diagnostic_display(struct l_dbus_message_iter *dict,
|
|||||||
if (!map->custom)
|
if (!map->custom)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
map->custom(&variant, key, margin, name_column_width,
|
if (!map->custom(&variant, key, margin, name_column_width,
|
||||||
value_column_width);
|
value_column_width))
|
||||||
|
goto parse_error;
|
||||||
|
|
||||||
/* custom should handle any units, so continue */
|
/* custom should handle any units, so continue */
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
case 's':
|
case 's':
|
||||||
l_dbus_message_iter_get_variant(&variant, "s",
|
if (!l_dbus_message_iter_get_variant(&variant, "s",
|
||||||
&s_value);
|
&s_value))
|
||||||
|
goto parse_error;
|
||||||
|
|
||||||
sprintf(display_text, "%s%-*s%-*s", margin,
|
sprintf(display_text, "%s%-*s%-*s", margin,
|
||||||
name_column_width, key,
|
name_column_width, key,
|
||||||
value_column_width, s_value);
|
value_column_width, s_value);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'u':
|
case 'u':
|
||||||
l_dbus_message_iter_get_variant(&variant, "u",
|
if (!l_dbus_message_iter_get_variant(&variant, "u",
|
||||||
&u_value);
|
&u_value))
|
||||||
|
goto parse_error;
|
||||||
|
|
||||||
sprintf(display_text, "%s%-*s%-*u", margin,
|
sprintf(display_text, "%s%-*s%-*u", margin,
|
||||||
name_column_width, key,
|
name_column_width, key,
|
||||||
value_column_width, u_value);
|
value_column_width, u_value);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'n':
|
case 'n':
|
||||||
l_dbus_message_iter_get_variant(&variant, "n",
|
if (!l_dbus_message_iter_get_variant(&variant, "n",
|
||||||
&n_value);
|
&n_value))
|
||||||
|
goto parse_error;
|
||||||
|
|
||||||
sprintf(display_text, "%s%-*s%-*i", margin,
|
sprintf(display_text, "%s%-*s%-*i", margin,
|
||||||
name_column_width, key,
|
name_column_width, key,
|
||||||
value_column_width, n_value);
|
value_column_width, n_value);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'y':
|
case 'y':
|
||||||
l_dbus_message_iter_get_variant(&variant, "y",
|
if (!l_dbus_message_iter_get_variant(&variant, "y",
|
||||||
&y_value);
|
&y_value))
|
||||||
|
goto parse_error;
|
||||||
|
|
||||||
sprintf(display_text, "%s%-*s%-*u", margin,
|
sprintf(display_text, "%s%-*s%-*u", margin,
|
||||||
name_column_width, key,
|
name_column_width, key,
|
||||||
value_column_width, y_value);
|
value_column_width, y_value);
|
||||||
@ -164,4 +176,9 @@ void diagnostic_display(struct l_dbus_message_iter *dict,
|
|||||||
else
|
else
|
||||||
display("%s\n", display_text);
|
display("%s\n", display_text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
|
||||||
|
parse_error:
|
||||||
|
display_error("Error parsing dignostics");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user