link-factory: avoid using 0 for invalid id

Use SPA_ID_INVALID instead of 0 when we fail to parse the port id
so that we don't accidentally match an internal port id.

See #1724
This commit is contained in:
Wim Taymans 2021-10-18 11:33:49 +02:00
parent 0651e12ad8
commit bd8ec29bb5

View file

@ -266,13 +266,14 @@ static struct pw_impl_port *find_port(struct pw_context *context,
struct pw_impl_node *node, enum spa_direction direction, const char *name) struct pw_impl_node *node, enum spa_direction direction, const char *name)
{ {
struct find_port find = { struct find_port find = {
.id = atoi(name), .id = SPA_ID_INVALID,
.name = name, .name = name,
.direction = direction, .direction = direction,
.node = node .node = node
}; };
spa_atou32(name, &find.id, 0);
if (find.id != 0) { if (find.id != SPA_ID_INVALID) {
struct pw_global *global = pw_context_find_global(context, find.id); struct pw_global *global = pw_context_find_global(context, find.id);
/* find port by global id */ /* find port by global id */
if (global != NULL && pw_global_is_type(global, PW_TYPE_INTERFACE_Port)) if (global != NULL && pw_global_is_type(global, PW_TYPE_INTERFACE_Port))
@ -280,7 +281,7 @@ static struct pw_impl_port *find_port(struct pw_context *context,
} }
if (node != NULL) { if (node != NULL) {
/* find port by local id */ /* find port by local id */
if (find.id != 0) { if (find.id != SPA_ID_INVALID) {
find.port = pw_impl_node_find_port(node, find.direction, find.id); find.port = pw_impl_node_find_port(node, find.direction, find.id);
if (find.port != NULL) if (find.port != NULL)
return find.port; return find.port;
@ -337,11 +338,12 @@ found:
static struct pw_impl_node *find_node(struct pw_context *context, const char *name) static struct pw_impl_node *find_node(struct pw_context *context, const char *name)
{ {
struct find_node find = { struct find_node find = {
.id = atoi(name), .id = SPA_ID_INVALID,
.name = name, .name = name,
}; };
spa_atou32(name, &find.id, 0);
if (find.id != 0) { if (find.id != SPA_ID_INVALID) {
struct pw_global *global = pw_context_find_global(context, find.id); struct pw_global *global = pw_context_find_global(context, find.id);
if (global != NULL && pw_global_is_type(global, PW_TYPE_INTERFACE_Node)) if (global != NULL && pw_global_is_type(global, PW_TYPE_INTERFACE_Node))
return pw_global_get_object(global); return pw_global_get_object(global);