Skip to content

Transfer used before initialization #1

@spookee0

Description

@spookee0

I'm trying to use libserard in my code. I successfully managed to send heartbeats. However, skis stopped moving when it came to receiving packets. Here's what I noticed: It seems the transfer structure is being used before initialization.

ret = rxAcceptTransfer(ins, reassembler, out_transfer);
if (ret == 1)
{
// copy the relevant metadata from the reassembler
// because the transfer is valid, the application takes ownership
// of the payload buffer.
memcpy(&out_transfer->metadata, &reassembler->metadata, sizeof(struct SerardTransferMetadata));
out_transfer->payload_extent = reassembler->payload_extent;
out_transfer->payload = reassembler->payload;
out_transfer->timestamp_usec = reassembler->timestamp_usec;
}

It seems possible that reassembler should be used instead of transfer?
const struct SerardTransferMetadata* const metadata = &transfer->metadata;

Also, the session state doesn't appear to be updating (only partially updating).
SERARD_PRIVATE bool rxSessionUpdate(struct SerardRx* const ins,
struct SerardInternalRxSession* const rxs,
const struct SerardRxTransfer* const transfer,
const SerardMicrosecond transfer_id_timeout_usec)
{
SERARD_ASSERT(ins != NULL);
SERARD_ASSERT(rxs != NULL);
SERARD_ASSERT(transfer != NULL);
const struct SerardTransferMetadata* metadata = &transfer->metadata;
// Accept the transfer if the new transfer ID is greater than the previous.
const bool tid_future = metadata->transfer_id > rxs->transfer_id;
// Accept (and restart the session) on transfer ID timeout.
const bool tid_timed_out = (transfer->timestamp_usec > rxs->transfer_timestamp_usec) &&
((transfer->timestamp_usec - rxs->transfer_timestamp_usec) > transfer_id_timeout_usec);
// Accept if the transfer ID is at least TRANSFER_ID_DELTA counts less than
// the previous one. This is used to hot-start the rx pipeline after a reboot.
const bool wrap = !tid_future && ((rxs->transfer_id - metadata->transfer_id) >= TRANSFER_ID_DELTA);
if (tid_timed_out)
{
rxs->transfer_id = metadata->transfer_id;
}
return tid_future || tid_timed_out || wrap;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions