tools: add some check when parsing the profile info

Fail when we can't parse the profile info to avoid using invalid
values.
This commit is contained in:
Wim Taymans 2021-03-27 20:37:26 +01:00
parent ae22852a9b
commit c85a04fb49
2 changed files with 20 additions and 17 deletions

View file

@ -88,17 +88,16 @@ struct point {
static int process_info(struct data *d, const struct spa_pod *pod, struct point *point) static int process_info(struct data *d, const struct spa_pod *pod, struct point *point)
{ {
spa_pod_parse_struct(pod, return spa_pod_parse_struct(pod,
SPA_POD_Long(&point->count), SPA_POD_Long(&point->count),
SPA_POD_Float(&point->cpu_load[0]), SPA_POD_Float(&point->cpu_load[0]),
SPA_POD_Float(&point->cpu_load[1]), SPA_POD_Float(&point->cpu_load[1]),
SPA_POD_Float(&point->cpu_load[2])); SPA_POD_Float(&point->cpu_load[2]));
return 0;
} }
static int process_clock(struct data *d, const struct spa_pod *pod, struct point *point) static int process_clock(struct data *d, const struct spa_pod *pod, struct point *point)
{ {
spa_pod_parse_struct(pod, return spa_pod_parse_struct(pod,
SPA_POD_Int(&point->clock.flags), SPA_POD_Int(&point->clock.flags),
SPA_POD_Int(&point->clock.id), SPA_POD_Int(&point->clock.id),
SPA_POD_Stringn(point->clock.name, sizeof(point->clock.name)), SPA_POD_Stringn(point->clock.name, sizeof(point->clock.name)),
@ -109,7 +108,6 @@ static int process_clock(struct data *d, const struct spa_pod *pod, struct point
SPA_POD_Long(&point->clock.delay), SPA_POD_Long(&point->clock.delay),
SPA_POD_Double(&point->clock.rate_diff), SPA_POD_Double(&point->clock.rate_diff),
SPA_POD_Long(&point->clock.next_nsec)); SPA_POD_Long(&point->clock.next_nsec));
return 0;
} }
static int process_driver_block(struct data *d, const struct spa_pod *pod, struct point *point) static int process_driver_block(struct data *d, const struct spa_pod *pod, struct point *point)
@ -117,16 +115,18 @@ static int process_driver_block(struct data *d, const struct spa_pod *pod, struc
char *name = NULL; char *name = NULL;
uint32_t driver_id = 0; uint32_t driver_id = 0;
struct measurement driver; struct measurement driver;
int res;
spa_zero(driver); spa_zero(driver);
spa_pod_parse_struct(pod, if ((res = spa_pod_parse_struct(pod,
SPA_POD_Int(&driver_id), SPA_POD_Int(&driver_id),
SPA_POD_String(&name), SPA_POD_String(&name),
SPA_POD_Long(&driver.prev_signal), SPA_POD_Long(&driver.prev_signal),
SPA_POD_Long(&driver.signal), SPA_POD_Long(&driver.signal),
SPA_POD_Long(&driver.awake), SPA_POD_Long(&driver.awake),
SPA_POD_Long(&driver.finish), SPA_POD_Long(&driver.finish),
SPA_POD_Int(&driver.status)); SPA_POD_Int(&driver.status))) < 0)
return res;
if (d->driver_id == 0) { if (d->driver_id == 0) {
d->driver_id = driver_id; d->driver_id = driver_id;
@ -171,17 +171,18 @@ static int process_follower_block(struct data *d, const struct spa_pod *pod, str
uint32_t id = 0; uint32_t id = 0;
const char *name = NULL; const char *name = NULL;
struct measurement m; struct measurement m;
int idx; int res, idx;
spa_zero(m); spa_zero(m);
spa_pod_parse_struct(pod, if ((res = spa_pod_parse_struct(pod,
SPA_POD_Int(&id), SPA_POD_Int(&id),
SPA_POD_String(&name), SPA_POD_String(&name),
SPA_POD_Long(&m.prev_signal), SPA_POD_Long(&m.prev_signal),
SPA_POD_Long(&m.signal), SPA_POD_Long(&m.signal),
SPA_POD_Long(&m.awake), SPA_POD_Long(&m.awake),
SPA_POD_Long(&m.finish), SPA_POD_Long(&m.finish),
SPA_POD_Int(&m.status)); SPA_POD_Int(&m.status))) < 0)
return res;
if ((idx = find_follower(d, id, name)) < 0) { if ((idx = find_follower(d, id, name)) < 0) {
if ((idx = add_follower(d, id, name)) < 0) { if ((idx = add_follower(d, id, name)) < 0) {

View file

@ -95,18 +95,17 @@ struct point {
static int process_info(struct data *d, const struct spa_pod *pod, struct driver *info) static int process_info(struct data *d, const struct spa_pod *pod, struct driver *info)
{ {
spa_pod_parse_struct(pod, return spa_pod_parse_struct(pod,
SPA_POD_Long(&info->count), SPA_POD_Long(&info->count),
SPA_POD_Float(&info->cpu_load[0]), SPA_POD_Float(&info->cpu_load[0]),
SPA_POD_Float(&info->cpu_load[1]), SPA_POD_Float(&info->cpu_load[1]),
SPA_POD_Float(&info->cpu_load[2]), SPA_POD_Float(&info->cpu_load[2]),
SPA_POD_Int(&info->xrun_count)); SPA_POD_Int(&info->xrun_count));
return 0;
} }
static int process_clock(struct data *d, const struct spa_pod *pod, struct driver *info) static int process_clock(struct data *d, const struct spa_pod *pod, struct driver *info)
{ {
spa_pod_parse_struct(pod, return spa_pod_parse_struct(pod,
SPA_POD_Int(&info->clock.flags), SPA_POD_Int(&info->clock.flags),
SPA_POD_Int(&info->clock.id), SPA_POD_Int(&info->clock.id),
SPA_POD_Stringn(info->clock.name, sizeof(info->clock.name)), SPA_POD_Stringn(info->clock.name, sizeof(info->clock.name)),
@ -117,7 +116,6 @@ static int process_clock(struct data *d, const struct spa_pod *pod, struct drive
SPA_POD_Long(&info->clock.delay), SPA_POD_Long(&info->clock.delay),
SPA_POD_Double(&info->clock.rate_diff), SPA_POD_Double(&info->clock.rate_diff),
SPA_POD_Long(&info->clock.next_nsec)); SPA_POD_Long(&info->clock.next_nsec));
return 0;
} }
static struct node *find_node(struct data *d, uint32_t id) static struct node *find_node(struct data *d, uint32_t id)
@ -162,9 +160,10 @@ static int process_driver_block(struct data *d, const struct spa_pod *pod, struc
uint32_t id = 0; uint32_t id = 0;
struct measurement m; struct measurement m;
struct node *n; struct node *n;
int res;
spa_zero(m); spa_zero(m);
spa_pod_parse_struct(pod, if ((res = spa_pod_parse_struct(pod,
SPA_POD_Int(&id), SPA_POD_Int(&id),
SPA_POD_String(&name), SPA_POD_String(&name),
SPA_POD_Long(&m.prev_signal), SPA_POD_Long(&m.prev_signal),
@ -172,7 +171,8 @@ static int process_driver_block(struct data *d, const struct spa_pod *pod, struc
SPA_POD_Long(&m.awake), SPA_POD_Long(&m.awake),
SPA_POD_Long(&m.finish), SPA_POD_Long(&m.finish),
SPA_POD_Int(&m.status), SPA_POD_Int(&m.status),
SPA_POD_Fraction(&m.latency)); SPA_POD_Fraction(&m.latency))) < 0)
return res;
if ((n = find_node(d, id)) == NULL) if ((n = find_node(d, id)) == NULL)
return -ENOENT; return -ENOENT;
@ -196,9 +196,10 @@ static int process_follower_block(struct data *d, const struct spa_pod *pod, str
const char *name = NULL; const char *name = NULL;
struct measurement m; struct measurement m;
struct node *n; struct node *n;
int res;
spa_zero(m); spa_zero(m);
spa_pod_parse_struct(pod, if ((res = spa_pod_parse_struct(pod,
SPA_POD_Int(&id), SPA_POD_Int(&id),
SPA_POD_String(&name), SPA_POD_String(&name),
SPA_POD_Long(&m.prev_signal), SPA_POD_Long(&m.prev_signal),
@ -206,7 +207,8 @@ static int process_follower_block(struct data *d, const struct spa_pod *pod, str
SPA_POD_Long(&m.awake), SPA_POD_Long(&m.awake),
SPA_POD_Long(&m.finish), SPA_POD_Long(&m.finish),
SPA_POD_Int(&m.status), SPA_POD_Int(&m.status),
SPA_POD_Fraction(&m.latency)); SPA_POD_Fraction(&m.latency))) < 0)
return res;
if ((n = find_node(d, id)) == NULL) if ((n = find_node(d, id)) == NULL)
return -ENOENT; return -ENOENT;