void smartcard_char_device_wakeup(SpiceCharDeviceInstance *sin) { SmartCardDeviceState* state = SPICE_CONTAINEROF( sin->st, SmartCardDeviceState, base); SpiceCharDeviceInterface *sif = SPICE_CONTAINEROF(sin->base.sif, SpiceCharDeviceInterface, base); VSCMsgHeader *vheader = (VSCMsgHeader*)state->buf; int n; int remaining; while ((n = sif->read(sin, state->buf_pos, state->buf_size - state->buf_used)) > 0) { state->buf_pos += n; state->buf_used += n; if (state->buf_used < sizeof(VSCMsgHeader)) { continue; } if (vheader->length > state->buf_size) { state->buf_size = MAX(state->buf_size*2, vheader->length + sizeof(VSCMsgHeader)); state->buf = spice_realloc(state->buf, state->buf_size); ASSERT(state->buf != NULL); } if (state->buf_used - sizeof(VSCMsgHeader) < vheader->length) { continue; } smartcard_char_device_on_message_from_device(state, vheader); remaining = state->buf_used - sizeof(VSCMsgHeader) > vheader->length; if (remaining > 0) { memcpy(state->buf, state->buf_pos, remaining); } state->buf_pos = state->buf; state->buf_used = remaining; } }
void *spice_realloc_n(void *mem, size_t n_blocks, size_t n_block_bytes) { if (SIZE_OVERFLOWS (n_blocks, n_block_bytes)) { MALLOC_ERROR("spice_realloc_n: overflow allocating %lu*%lu bytes", (unsigned long)n_blocks, (unsigned long)n_block_bytes); } return spice_realloc(mem, n_blocks * n_block_bytes); }
static void smartcard_read_buf_prepare(SmartCardDeviceState *state, VSCMsgHeader *vheader) { uint32_t msg_len; msg_len = ntohl(vheader->length); if (msg_len > state->buf_size) { state->buf_size = MAX(state->buf_size * 2, msg_len + sizeof(VSCMsgHeader)); state->buf = spice_realloc(state->buf, state->buf_size); } }
RedsSaslError reds_sasl_handle_auth_startlen(RedsStream *stream, AsyncReadDone read_cb, void *opaque) { RedsSASL *sasl = &stream->priv->sasl; spice_debug("Got client start len %d", sasl->len); if (sasl->len > SASL_DATA_MAX_LEN) { spice_warning("Too much SASL data %d", sasl->len); return REDS_SASL_ERROR_INVALID_DATA; } if (sasl->len == 0) { return REDS_SASL_ERROR_RETRY; } sasl->data = spice_realloc(sasl->data, sasl->len); reds_stream_async_read(stream, (uint8_t *)sasl->data, sasl->len, read_cb, opaque); return REDS_SASL_ERROR_OK; }
RedsSaslError reds_sasl_handle_auth_steplen(RedsStream *stream, AsyncReadDone read_cb, void *opaque) { RedsSASL *sasl = &stream->priv->sasl; spice_debug("Got steplen %d", sasl->len); if (sasl->len > SASL_DATA_MAX_LEN) { spice_warning("Too much SASL data %d", sasl->len); return REDS_SASL_ERROR_INVALID_DATA; } if (sasl->len == 0) { read_cb(opaque); /* FIXME: can't report potential errors correctly here, * but read_cb() will have done the needed RedLinkInfo cleanups * if an error occurs, so the caller should not need to do more * treatment */ return REDS_SASL_ERROR_OK; } else { sasl->data = spice_realloc(sasl->data, sasl->len); reds_stream_async_read(stream, (uint8_t *)sasl->data, sasl->len, read_cb, opaque); return REDS_SASL_ERROR_OK; } }