Skip to content

Commit

Permalink
fix: explicit query data stealking
Browse files Browse the repository at this point in the history
  • Loading branch information
jean-roland committed Dec 4, 2024
1 parent 01fbc12 commit 730d992
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/session/queryable.c
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,15 @@ static z_result_t _z_session_queryable_get_infos(_z_session_t *zn, const _z_keye
return _Z_RES_OK;
}

static inline void _z_queryable_query_steal_data(_z_query_t *query, _z_session_rc_t *zsrc, _z_msg_query_t *msgq,
_z_keyexpr_t *key, uint32_t qid, bool anyke) {
// Steal received data in query
*query = _z_query_alias(&msgq->_ext_value, key, &msgq->_parameters, zsrc, qid, &msgq->_ext_attachment, anyke);
msgq->_ext_value = _z_value_null();
msgq->_ext_attachment = _z_bytes_null();
msgq->_parameters = _z_slice_null();
}

static z_result_t _z_trigger_queryables_inner(_z_session_rc_t *zsrc, _z_msg_query_t *msgq, _z_keyexpr_t *q_key,
uint32_t qid) {
_z_session_t *zn = _Z_RC_IN_VAL(zsrc);
Expand All @@ -224,17 +233,12 @@ static z_result_t _z_trigger_queryables_inner(_z_session_rc_t *zsrc, _z_msg_quer
}
}
// Build the z_query
_z_query_t q =
_z_query_alias(&msgq->_ext_value, &key, &msgq->_parameters, zsrc, qid, &msgq->_ext_attachment, anyke);
_z_query_t q = _z_query_null();
_z_query_rc_t query = _z_query_rc_new_from_val(&q);
if (_Z_RC_IS_NULL(&query)) {
return _Z_ERR_SYSTEM_OUT_OF_MEMORY;
}
// Clear values to avoid double free
*q_key = _z_keyexpr_null();
msgq->_ext_value = _z_value_null();
msgq->_ext_attachment = _z_bytes_null();
msgq->_parameters = _z_slice_null();
_z_queryable_query_steal_data(_Z_RC_IN_VAL(&query), zsrc, msgq, &key, qid, anyke);
// Parse session_queryable svec
for (size_t i = 0; i < qle_nb; i++) {
_z_queryable_infos_t *qle_info = _z_queryable_infos_svec_get(&qles, i);
Expand All @@ -253,8 +257,7 @@ z_result_t _z_trigger_queryables(_z_session_rc_t *zsrc, _z_msg_query_t *msgq, _z
z_result_t ret = _z_trigger_queryables_inner(zsrc, msgq, q_key, qid);
// Clean up
_z_keyexpr_clear(q_key);
_z_encoding_clear(&msgq->_ext_value.encoding);
_z_bytes_drop(&msgq->_ext_value.payload);
_z_value_clear(&msgq->_ext_value);
_z_bytes_drop(&msgq->_ext_attachment);
_z_slice_clear(&msgq->_parameters);
return ret;
Expand Down

0 comments on commit 730d992

Please sign in to comment.