Commit 60d6418b authored by Job Vranish's avatar Job Vranish
Browse files

added a check in the sink_cb so that it correctly handles a read that's smaller than the header

parent b4069cc8
Loading
Loading
Loading
Loading
+29 −14
Original line number Diff line number Diff line
@@ -97,7 +97,13 @@ STATIC bus_sink_cb_res_t sink_cb(uint8_t *read_buf,
    }
    case STATE_AWAITING_HEADER:
    {
        if (unpack_header(read_buf, read_size, &si->header))
        memcpy(&si->buf[si->accumulated], read_buf, read_size);
        si->accumulated += read_size;

        uint32_t remaining = PDU_HEADER_LEN - si->accumulated;

        if (remaining == 0) {
            if (unpack_header(&si->buf[0], PDU_HEADER_LEN, &si->header))
            {
                si->accumulated = 0;
                si->unpack_status = UNPACK_ERROR_SUCCESS;
@@ -116,6 +122,14 @@ STATIC bus_sink_cb_res_t sink_cb(uint8_t *read_buf,
                };
                return res;
            }
        }
        else
        {
            bus_sink_cb_res_t res = {
                .next_read = remaining,
            };
            return res;
        }
        break;
    } 
    case STATE_AWAITING_BODY:
@@ -127,6 +141,7 @@ STATIC bus_sink_cb_res_t sink_cb(uint8_t *read_buf,

        if (remaining == 0) {
            si->state = STATE_AWAITING_HEADER;
            si->accumulated = 0;
            bus_sink_cb_res_t res = {
                .next_read = sizeof(KineticPDUHeader),
                // returning the whole si, because we need access to the pdu header as well