[
https://issues.apache.org/jira/browse/PROTON-1832?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16446333#comment-16446333
]
Alan Conway commented on PROTON-1832:
-------------------------------------
There are 2 bugs:
1. Client side: pni_process does all pending link opens before all pending link
closes, it does not respect the order of individual open/close calls in the
code. For links with distinct names that's not a big problem, but for links
with the same name it is.
For example if l1 and l2 are both pn_links with name "x" then this sequence:
{code:java}
open(l1); close(l1); open(l2){code}
generates this illegal protocol sequence:
{code:java}
attach("x"); attach("x"); detach(0) // 0 is the handle assigned to "x"{code}
instead of the intended legal sequence:
{code:java}
attach("x"); detach(0); attach("x") // detach(0) detaches the first "x" so
second "x" is allowed{code}
NOTE: This applies to all endpoints, not just links.
2. Server side: the server does not guard against illegal attach sequences like
1. above, such sequences can crash the server. The server ends up with multiple
handle entries in the session hash referring to the same link object. If that
object is deleted, only one of the entries is cleared and the others now have
dangling pointers.
Not confirmed but a similar bug may affect session handles also.
> [c] duplicate link names cause invalid read in pn_transport_unbind_handles
> --------------------------------------------------------------------------
>
> Key: PROTON-1832
> URL: https://issues.apache.org/jira/browse/PROTON-1832
> Project: Qpid Proton
> Issue Type: Bug
> Components: proton-c
> Affects Versions: proton-c-0.21.0
> Reporter: Alan Conway
> Assignee: Alan Conway
> Priority: Major
> Fix For: proton-j-0.27.0
>
>
> Proton has an invalid read error in pn_transport_unbind_handles under
> specific circumstances where the same name is used to create 2 different
> incoming links on the same session.
> This patch demonstrates
> {code:java}
> 1 file changed, 43 insertions(+), 2 deletions(-)
> c/tests/connection_driver.c | 45 +++++++++++++++++++++++++++++++++++++++++++--
> modified c/tests/connection_driver.c
> @@ -48,6 +48,24 @@ static pn_event_type_t open_handler(test_handler_t *th,
> pn_event_t *e) {
> return PN_EVENT_NONE;
> }
>
> +/* Like open_handler but also reply to REMOTE_CLOSE */
> +static pn_event_type_t open_close_handler(test_handler_t *th, pn_event_t *e)
> {
> + switch (pn_event_type(e)) {
> + case PN_CONNECTION_REMOTE_CLOSE:
> + pn_connection_open(pn_event_connection(e));
> + break;
> + case PN_SESSION_REMOTE_CLOSE:
> + pn_session_open(pn_event_session(e));
> + break;
> + case PN_LINK_REMOTE_CLOSE:
> + pn_link_close(pn_event_link(e));
> + break;
> + default:
> + return open_handler(th, e);
> + }
> + return PN_EVENT_NONE;
> +}
> +
> /* Handler that returns control on PN_DELIVERY and stores the delivery on
> the handler */
> static pn_event_type_t delivery_handler(test_handler_t *th, pn_event_t *e) {
> switch (pn_event_type(e)) {
> @@ -442,6 +458,30 @@ static void test_session_flow_control(test_t *t) {
> test_connection_drivers_destroy(&client, &server);
> }
>
> +/* Regression test for crash caused by using the same name for multiple
> links on same session. */
> +static void test_duplicate_link(test_t *t) {
> + /* Set up the initial link */
> + test_connection_driver_t client, server;
> + test_connection_drivers_init(t, &client, open_close_handler, &server,
> open_close_handler);
> + pn_connection_open(client.driver.connection);
> + pn_session_t *ssn = pn_session(client.driver.connection);
> + pn_session_open(ssn);
> + pn_link_t *x = pn_sender(ssn, "x");
> + pn_link_open(x);
> + /* Close the link and open a new link with same name.
> + NOTE: close and duplicate open must be in the same batch of events
> + */
> + pn_link_close(x);
> + pn_link_open(pn_sender(ssn, "x"));
> + test_connection_drivers_run(&client, &server);
> + /* At this point the server has 2 handle map entries for the same link.
> + Freeing the link is correct, refcounting will keep it in memory,
> + but the extra handle map entry will cause a core dump in
> pn_transport_unbind_handles
> + */
> + pn_link_free(server.handler.link);
> + test_connection_drivers_destroy(&client, &server);
> +}
> +
> int main(int argc, char **argv) {
> int failed = 0;
> RUN_ARGV_TEST(failed, t, test_message_transfer(&t));
> @@ -449,5 +489,6 @@ int main(int argc, char **argv) {
> RUN_ARGV_TEST(failed, t, test_message_abort(&t));
> RUN_ARGV_TEST(failed, t, test_message_abort_mixed(&t));
> RUN_ARGV_TEST(failed, t, test_session_flow_control(&t));
> + RUN_ARGV_TEST(failed, t, test_duplicate_link(&t));
> return failed;
> }
> {code}
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]