Skip to content

Commit

Permalink
QUIC OBJ: Use QUIC_OBJ pointer for parent references
Browse files Browse the repository at this point in the history
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Neil Horman <nhorman@openssl.org>
(Merged from #23334)
  • Loading branch information
hlandau committed Apr 19, 2024
1 parent 5300a20 commit e1d77f8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 20 deletions.
20 changes: 5 additions & 15 deletions ssl/quic/quic_obj.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ int ossl_quic_obj_init(QUIC_OBJ *obj,
if (!ossl_ssl_init(&obj->ssl, ctx, ctx->method, type))
goto err;

obj->parent_obj = parent_obj;
obj->parent_obj = (QUIC_OBJ *)parent_obj;
obj->is_event_leader = is_event_leader;
obj->is_port_leader = is_port_leader;
obj->engine = engine;
Expand All @@ -51,22 +51,12 @@ int ossl_quic_obj_init(QUIC_OBJ *obj,
return 0;
}

static ossl_inline QUIC_OBJ *
ssl_to_obj(SSL *ssl)
{
if (ssl == NULL)
return NULL;

assert(IS_QUIC(ssl));
return (QUIC_OBJ *)ssl;
}

static int obj_update_cache(QUIC_OBJ *obj)
{
QUIC_OBJ *p;

for (p = obj; p != NULL && !p->is_event_leader;
p = ssl_to_obj(p->parent_obj))
p = p->parent_obj)
if (!ossl_assert(p == obj || p->init_done))
return 0;

Expand All @@ -77,13 +67,13 @@ static int obj_update_cache(QUIC_OBJ *obj)
* Offset of ->ssl is guaranteed to be 0 but the NULL check makes ubsan
* happy.
*/
obj->cached_event_leader = (p != NULL) ? &p->ssl : NULL;
obj->cached_event_leader = p;
obj->engine = p->engine;

for (p = obj; p != NULL && !p->is_port_leader;
p = ssl_to_obj(p->parent_obj));
p = p->parent_obj);

obj->cached_port_leader = (p != NULL) ? &p->ssl : NULL;
obj->cached_port_leader = p;
obj->port = (p != NULL) ? p->port : NULL;
return 1;
}
Expand Down
14 changes: 9 additions & 5 deletions ssl/quic/quic_obj_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,12 @@ struct quic_obj_st {
* Pointer to a parent APL object in a QUIC APL object hierarchy, or NULL if
* this is the root object.
*/
SSL *parent_obj;
QUIC_OBJ *parent_obj;

/* invariant: != NULL */
SSL *cached_event_leader;
QUIC_OBJ *cached_event_leader;
/* invariant: != NULL iff this is a port leader or subsidiary object */
SSL *cached_port_leader;
QUIC_OBJ *cached_port_leader;

/*
* Points to the QUIC_ENGINE instance. Always equals
Expand Down Expand Up @@ -257,7 +257,9 @@ static ossl_inline ossl_unused SSL *
ossl_quic_obj_get0_event_leader(const QUIC_OBJ *obj)
{
assert(obj->init_done);
return obj->cached_event_leader;
return obj->cached_event_leader != NULL
? &obj->cached_event_leader->ssl
: NULL;
}

/*
Expand All @@ -268,7 +270,9 @@ static ossl_inline ossl_unused SSL *
ossl_quic_obj_get0_port_leader(const QUIC_OBJ *obj)
{
assert(obj->init_done);
return obj->cached_port_leader;
return obj->cached_port_leader != NULL
? &obj->cached_port_leader->ssl
: NULL;
}

# endif
Expand Down

0 comments on commit e1d77f8

Please sign in to comment.