module-protocol-native: make demarshaling safe vs. reentering

The message structures returned by pw_protocol_native_connection_get_next
point to data that is contained in the buffer of the connection.

The data was invalidated when pw_protocol_native_connection_get_next was
called the next time, which made the connection loop non-reentrant, in
cases where it was re-entered from demarshal callbacks.

Fix this by allocating new buffers when reentering and stashing the old
buffers onto a stack. The returned message structure is also stored on
the stack to make lifetimes to match.
This commit is contained in:
Pauli Virtanen 2021-01-10 16:41:49 +02:00 committed by Wim Taymans
parent 09a690b123
commit 23f010541f
3 changed files with 156 additions and 3 deletions

View file

@ -230,7 +230,10 @@ process_messages(struct client_data *data)
continue;
}
if ((res = demarshal[msg->opcode].func(resource, msg)) < 0)
pw_protocol_native_connection_enter(conn);
res = demarshal[msg->opcode].func(resource, msg);
pw_protocol_native_connection_leave(conn);
if (res < 0)
goto invalid_message;
}
res = 0;
@ -759,7 +762,9 @@ process_remote(struct client *impl)
continue;
}
proxy->refcount++;
pw_protocol_native_connection_enter(conn);
res = demarshal[msg->opcode].func(proxy, msg);
pw_protocol_native_connection_leave(conn);
pw_proxy_unref(proxy);
if (res < 0) {