Found by Coverity Scan. A graph's 'can_consume' state must only
be sampled after the graph argument's validation. The error paths
must also repeat that check on restoration of the state.
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
struct bt_component *upstream_component = NULL;
struct bt_component *downstream_component = NULL;
enum bt_component_status component_status;
struct bt_component *upstream_component = NULL;
struct bt_component *downstream_component = NULL;
enum bt_component_status component_status;
- const bt_bool init_can_consume = graph->can_consume;
+ bt_bool init_can_consume;
if (!graph) {
BT_LOGW_STR("Invalid parameter: graph is NULL.");
status = BT_GRAPH_STATUS_INVALID;
goto end;
}
if (!graph) {
BT_LOGW_STR("Invalid parameter: graph is NULL.");
status = BT_GRAPH_STATUS_INVALID;
goto end;
}
+ init_can_consume = graph->can_consume;
if (!upstream_port) {
BT_LOGW_STR("Invalid parameter: upstream port is NULL.");
if (!upstream_port) {
BT_LOGW_STR("Invalid parameter: upstream port is NULL.");
bt_put(upstream_component);
bt_put(downstream_component);
bt_put(connection);
bt_put(upstream_component);
bt_put(downstream_component);
bt_put(connection);
- graph->can_consume = init_can_consume;
+ if (graph) {
+ graph->can_consume = init_can_consume;
+ }
end:
BT_LOGV("Graph ran: status=%s", bt_graph_status_string(status));
end:
BT_LOGV("Graph ran: status=%s", bt_graph_status_string(status));
- graph->can_consume = BT_TRUE;
+ if (graph) {
+ graph->can_consume = BT_TRUE;
+ }
struct bt_component *component = NULL;
enum bt_component_class_type type;
size_t i;
struct bt_component *component = NULL;
enum bt_component_class_type type;
size_t i;
- const bt_bool init_can_consume = graph->can_consume;
+ bt_bool init_can_consume;
graph_status = BT_GRAPH_STATUS_INVALID;
goto end;
}
graph_status = BT_GRAPH_STATUS_INVALID;
goto end;
}
+ init_can_consume = graph->can_consume;
if (!component_class) {
BT_LOGW_STR("Invalid parameter: component class is NULL.");
if (!component_class) {
BT_LOGW_STR("Invalid parameter: component class is NULL.");
end:
bt_put(component);
bt_put(params);
end:
bt_put(component);
bt_put(params);
- graph->can_consume = init_can_consume;
+ if (graph) {
+ graph->can_consume = init_can_consume;
+ }
int bt_graph_remove_unconnected_component(struct bt_graph *graph,
struct bt_component *component)
{
int bt_graph_remove_unconnected_component(struct bt_graph *graph,
struct bt_component *component)
{
- const bt_bool init_can_consume = graph->can_consume;
+ bt_bool init_can_consume;
int64_t count;
uint64_t i;
int ret = 0;
int64_t count;
uint64_t i;
int ret = 0;
assert(component->base.ref_count.count == 0);
assert(bt_component_borrow_graph(component) == graph);
assert(component->base.ref_count.count == 0);
assert(bt_component_borrow_graph(component) == graph);
+ init_can_consume = graph->can_consume;
count = bt_component_get_input_port_count(component);
for (i = 0; i < count; i++) {
count = bt_component_get_input_port_count(component);
for (i = 0; i < count; i++) {