From 92ab55c5e1ca08d63d7ac2e51f0e996ad69f1776 Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Fri, 27 Feb 2026 20:04:43 +0100 Subject: [PATCH] [winpr,stream] Add Stream_ResetPosition A helper function that does not require return checks, in contrast to Stream_SetPosition, which might fail. --- channels/ainput/server/ainput_main.c | 4 +-- channels/audin/client/audin_main.c | 4 +-- channels/audin/server/audin.c | 2 +- channels/client/addin.c | 2 +- channels/cliprdr/server/cliprdr_main.c | 6 ++-- channels/disp/server/disp_main.c | 4 +-- channels/drdynvc/client/drdynvc_main.c | 10 +++---- channels/echo/server/echo_main.c | 2 +- channels/encomsp/client/encomsp_main.c | 2 +- channels/encomsp/server/encomsp_main.c | 4 +-- channels/gfxredir/server/gfxredir_main.c | 4 +-- channels/location/server/location_main.c | 2 +- channels/printer/client/printer_main.c | 2 +- channels/rail/client/rail_orders.c | 2 +- channels/rail/server/rail_main.c | 2 +- channels/rdpdr/client/rdpdr_main.c | 2 +- channels/rdpdr/server/rdpdr_main.c | 4 +-- channels/rdpecam/client/camera_device_main.c | 4 +-- .../server/camera_device_enumerator_main.c | 2 +- channels/rdpecam/server/camera_device_main.c | 2 +- channels/rdpei/client/rdpei_main.c | 2 +- channels/rdpei/server/rdpei_main.c | 14 ++++----- channels/rdpemsc/server/mouse_cursor_main.c | 2 +- channels/rdpgfx/server/rdpgfx_main.c | 4 +-- channels/rdpsnd/client/rdpsnd_main.c | 6 ++-- channels/rdpsnd/server/rdpsnd_main.c | 24 +++++++-------- channels/remdesk/client/remdesk_main.c | 2 +- channels/remdesk/server/remdesk_main.c | 4 +-- channels/telemetry/server/telemetry_main.c | 2 +- channels/tsmf/client/tsmf_main.c | 2 +- channels/urbdrc/client/data_transfer.c | 4 +-- channels/urbdrc/common/urbdrc_helpers.c | 2 +- channels/video/client/video_main.c | 4 +-- libfreerdp/codec/bitmap.c | 10 +++---- libfreerdp/codec/dsp.c | 8 ++--- libfreerdp/codec/dsp_ffmpeg.c | 2 +- libfreerdp/codec/interleaved.c | 2 +- libfreerdp/codec/progressive.c | 2 +- libfreerdp/core/fastpath.c | 10 +++---- libfreerdp/core/freerdp.c | 2 +- libfreerdp/core/gateway/rdg.c | 4 +-- libfreerdp/core/gateway/rpc_client.c | 10 +++---- libfreerdp/core/gateway/websocket.c | 10 +++---- libfreerdp/core/message.c | 2 +- libfreerdp/core/nla.c | 2 +- libfreerdp/core/rdp.c | 12 ++++---- libfreerdp/core/server.c | 8 ++--- libfreerdp/core/streamdump.c | 2 +- libfreerdp/core/transport.c | 4 +-- libfreerdp/emu/scard/smartcard_virtual_gids.c | 10 ++----- libfreerdp/utils/rdpdr_utils.c | 5 ++-- libfreerdp/utils/test/TestEncodedTypes.c | 15 +++------- server/Mac/mf_peer.c | 2 +- server/Sample/sfreerdp.c | 6 ++-- server/Windows/wf_update.c | 2 +- server/proxy/channels/pf_channel_drdynvc.c | 4 +-- server/proxy/channels/pf_channel_rdpdr.c | 16 +++++----- server/proxy/channels/pf_channel_smartcard.c | 2 +- .../modules/bitmap-filter/bitmap-filter.cpp | 2 +- server/proxy/pf_channel.c | 2 +- server/proxy/pf_client.c | 2 +- server/shadow/shadow_client.c | 4 +-- winpr/include/winpr/stream.h | 14 +++++++++ winpr/libwinpr/utils/collections/StreamPool.c | 2 +- winpr/libwinpr/utils/test/TestStream.c | 30 +++++++++---------- 65 files changed, 175 insertions(+), 171 deletions(-) diff --git a/channels/ainput/server/ainput_main.c b/channels/ainput/server/ainput_main.c index f8cb971eb..eb1740d9a 100644 --- a/channels/ainput/server/ainput_main.c +++ b/channels/ainput/server/ainput_main.c @@ -165,7 +165,7 @@ static UINT ainput_server_send_version(ainput_server* ainput) s = ainput->buffer; WINPR_ASSERT(s); - Stream_SetPosition(s, 0); + Stream_ResetPosition(s); if (!Stream_EnsureCapacity(s, 10)) { WLog_WARN(TAG, "[%s] out of memory", AINPUT_DVC_CHANNEL_NAME); @@ -446,7 +446,7 @@ static UINT ainput_process_message(ainput_server* ainput) wStream* s = ainput->buffer; WINPR_ASSERT(s); - Stream_SetPosition(s, 0); + Stream_ResetPosition(s); const BOOL rc = WTSVirtualChannelRead(ainput->ainput_channel, 0, nullptr, 0, &BytesReturned); if (!rc) goto out; diff --git a/channels/audin/client/audin_main.c b/channels/audin/client/audin_main.c index dfd1e0d9b..9eb71a47a 100644 --- a/channels/audin/client/audin_main.c +++ b/channels/audin/client/audin_main.c @@ -275,7 +275,7 @@ static UINT audin_process_formats(AUDIN_PLUGIN* audin, AUDIN_CHANNEL_CALLBACK* c } cbSizeFormatsPacket = (UINT32)Stream_GetPosition(out); - Stream_SetPosition(out, 0); + Stream_ResetPosition(out); Stream_Write_UINT8(out, MSG_SNDIN_FORMATS); /* Header (1 byte) */ Stream_Write_UINT32(out, callback->formats_count); /* NumFormats (4 bytes) */ Stream_Write_UINT32(out, cbSizeFormatsPacket); /* cbSizeFormatsPacket (4 bytes) */ @@ -366,7 +366,7 @@ static UINT audin_receive_wave_data(const AUDIO_FORMAT* format, const BYTE* data if (!audin->attached) return CHANNEL_RC_OK; - Stream_SetPosition(audin->data, 0); + Stream_ResetPosition(audin->data); if (!Stream_EnsureRemainingCapacity(audin->data, 1)) return CHANNEL_RC_NO_MEMORY; diff --git a/channels/audin/server/audin.c b/channels/audin/server/audin.c index aa3b3a115..c6259110c 100644 --- a/channels/audin/server/audin.c +++ b/channels/audin/server/audin.c @@ -376,7 +376,7 @@ static DWORD WINAPI audin_server_thread_func(LPVOID arg) if (status == WAIT_OBJECT_0) break; - Stream_SetPosition(s, 0); + Stream_ResetPosition(s); if (!WTSVirtualChannelRead(audin->audin_channel, 0, nullptr, 0, &BytesReturned)) { diff --git a/channels/client/addin.c b/channels/client/addin.c index cc5fd880b..6ba16970b 100644 --- a/channels/client/addin.c +++ b/channels/client/addin.c @@ -702,7 +702,7 @@ UINT channel_client_post_message(void* MsgsHandle, LPVOID pData, UINT32 dataLeng internals->data_in = nullptr; Stream_SealLength(data_in); - Stream_SetPosition(data_in, 0); + Stream_ResetPosition(data_in); if ((freerdp_settings_get_uint32(internals->ctx->settings, FreeRDP_ThreadingFlags) & THREADING_FLAGS_DISABLE_THREADS) != 0) diff --git a/channels/cliprdr/server/cliprdr_main.c b/channels/cliprdr/server/cliprdr_main.c index 446edf5fd..ac9339891 100644 --- a/channels/cliprdr/server/cliprdr_main.c +++ b/channels/cliprdr/server/cliprdr_main.c @@ -1105,7 +1105,7 @@ static UINT cliprdr_server_read(CliprdrServerContext* context) if (Stream_GetPosition(s) >= CLIPRDR_HEADER_LENGTH) { position = Stream_GetPosition(s); - Stream_SetPosition(s, 0); + Stream_ResetPosition(s); Stream_Read_UINT16(s, header.msgType); /* msgType (2 bytes) */ Stream_Read_UINT16(s, header.msgFlags); /* msgFlags (2 bytes) */ Stream_Read_UINT32(s, header.dataLen); /* dataLen (4 bytes) */ @@ -1158,7 +1158,7 @@ static UINT cliprdr_server_read(CliprdrServerContext* context) return error; } - Stream_SetPosition(s, 0); + Stream_ResetPosition(s); /* check for trailing zero bytes */ status = WaitForSingleObject(cliprdr->ChannelEvent, 0); @@ -1190,7 +1190,7 @@ static UINT cliprdr_server_read(CliprdrServerContext* context) if (!header.msgType) { /* ignore trailing bytes */ - Stream_SetPosition(s, 0); + Stream_ResetPosition(s); } } else diff --git a/channels/disp/server/disp_main.c b/channels/disp/server/disp_main.c index a2bdd96a0..d100bbba2 100644 --- a/channels/disp/server/disp_main.c +++ b/channels/disp/server/disp_main.c @@ -291,7 +291,7 @@ static UINT disp_server_handle_messages(DispServerContext* context) } /* Consume channel event only after the disp dynamic channel is ready */ - Stream_SetPosition(s, 0); + Stream_ResetPosition(s); if (!WTSVirtualChannelRead(priv->disp_channel, 0, nullptr, 0, &BytesReturned)) { @@ -323,7 +323,7 @@ static UINT disp_server_handle_messages(DispServerContext* context) } Stream_SetLength(s, BytesReturned); - Stream_SetPosition(s, 0); + Stream_ResetPosition(s); while (Stream_GetPosition(s) < Stream_Length(s)) { diff --git a/channels/drdynvc/client/drdynvc_main.c b/channels/drdynvc/client/drdynvc_main.c index fb6b0d7d6..fee3f6940 100644 --- a/channels/drdynvc/client/drdynvc_main.c +++ b/channels/drdynvc/client/drdynvc_main.c @@ -879,7 +879,7 @@ static UINT dvcman_receive_channel_data(DVCMAN_CHANNEL* channel, wStream* data, if (Stream_GetPosition(channel->dvc_data) >= channel->dvc_data_length) { Stream_SealLength(channel->dvc_data); - Stream_SetPosition(channel->dvc_data, 0); + Stream_ResetPosition(channel->dvc_data); status = dvcman_call_on_receive(channel, channel->dvc_data); Stream_Release(channel->dvc_data); @@ -1001,7 +1001,7 @@ static UINT drdynvc_write_data(drdynvcPlugin* drdynvc, UINT32 ChannelId, const B } else if (dataSize <= CHANNEL_CHUNK_LENGTH - pos) { - Stream_SetPosition(data_out, 0); + Stream_ResetPosition(data_out); Stream_Write_UINT8(data_out, (DATA_PDU << 4) | cbChId); Stream_SetPosition(data_out, pos); Stream_Write(data_out, data, dataSize); @@ -1012,7 +1012,7 @@ static UINT drdynvc_write_data(drdynvcPlugin* drdynvc, UINT32 ChannelId, const B /* Fragment the data */ cbLen = drdynvc_write_variable_uint(data_out, dataSize); pos = Stream_GetPosition(data_out); - Stream_SetPosition(data_out, 0); + Stream_ResetPosition(data_out); const INT32 pdu = (DATA_FIRST_PDU << 4) | cbChId | (cbLen << 2); Stream_Write_UINT8(data_out, WINPR_ASSERTING_INT_CAST(UINT8, pdu)); @@ -1042,7 +1042,7 @@ static UINT drdynvc_write_data(drdynvcPlugin* drdynvc, UINT32 ChannelId, const B Stream_SetPosition(data_out, 1); cbChId = drdynvc_write_variable_uint(data_out, ChannelId); pos = Stream_GetPosition(data_out); - Stream_SetPosition(data_out, 0); + Stream_ResetPosition(data_out); Stream_Write_UINT8(data_out, (DATA_PDU << 4) | cbChId); Stream_SetPosition(data_out, pos); @@ -1576,7 +1576,7 @@ static UINT drdynvc_virtual_channel_event_data_received(drdynvcPlugin* drdynvc, drdynvc->data_in = nullptr; Stream_SealLength(data_in); - Stream_SetPosition(data_in, 0); + Stream_ResetPosition(data_in); if (drdynvc->async) { diff --git a/channels/echo/server/echo_main.c b/channels/echo/server/echo_main.c index 6d21464d2..5a92d612e 100644 --- a/channels/echo/server/echo_main.c +++ b/channels/echo/server/echo_main.c @@ -238,7 +238,7 @@ static DWORD WINAPI echo_server_thread_func(LPVOID arg) if (status == WAIT_OBJECT_0) break; - Stream_SetPosition(s, 0); + Stream_ResetPosition(s); if (!WTSVirtualChannelRead(echo->echo_channel, 0, nullptr, 0, &BytesReturned)) { WLog_ERR(TAG, "WTSVirtualChannelRead failed!"); diff --git a/channels/encomsp/client/encomsp_main.c b/channels/encomsp/client/encomsp_main.c index 7c9c40e04..c24aed857 100644 --- a/channels/encomsp/client/encomsp_main.c +++ b/channels/encomsp/client/encomsp_main.c @@ -975,7 +975,7 @@ static UINT encomsp_virtual_channel_event_data_received(encomspPlugin* encomsp, encomsp->data_in = nullptr; Stream_SealLength(data_in); - Stream_SetPosition(data_in, 0); + Stream_ResetPosition(data_in); if (!MessageQueue_Post(encomsp->queue, nullptr, 0, (void*)data_in, nullptr)) { diff --git a/channels/encomsp/server/encomsp_main.c b/channels/encomsp/server/encomsp_main.c index ec3399f6a..0bfb4a0c1 100644 --- a/channels/encomsp/server/encomsp_main.c +++ b/channels/encomsp/server/encomsp_main.c @@ -239,7 +239,7 @@ static DWORD WINAPI encomsp_server_thread(LPVOID arg) if (header->Length >= Stream_GetPosition(s)) { Stream_SealLength(s); - Stream_SetPosition(s, 0); + Stream_ResetPosition(s); if ((error = encomsp_server_receive_pdu(context, s))) { @@ -248,7 +248,7 @@ static DWORD WINAPI encomsp_server_thread(LPVOID arg) break; } - Stream_SetPosition(s, 0); + Stream_ResetPosition(s); } } } diff --git a/channels/gfxredir/server/gfxredir_main.c b/channels/gfxredir/server/gfxredir_main.c index c5cf94fb2..93dd38fa9 100644 --- a/channels/gfxredir/server/gfxredir_main.c +++ b/channels/gfxredir/server/gfxredir_main.c @@ -223,7 +223,7 @@ static UINT gfxredir_server_handle_messages(GfxRedirServerContext* context) /* Consume channel event only after the dynamic channel is ready */ if (priv->isReady) { - Stream_SetPosition(s, 0); + Stream_ResetPosition(s); DWORD BytesReturned = 0; if (!WTSVirtualChannelRead(priv->gfxredir_channel, 0, nullptr, 0, &BytesReturned)) @@ -253,7 +253,7 @@ static UINT gfxredir_server_handle_messages(GfxRedirServerContext* context) } Stream_SetLength(s, BytesReturned); - Stream_SetPosition(s, 0); + Stream_ResetPosition(s); while (Stream_GetPosition(s) < Stream_Length(s)) { diff --git a/channels/location/server/location_main.c b/channels/location/server/location_main.c index b4cf40f1a..fd9429db5 100644 --- a/channels/location/server/location_main.c +++ b/channels/location/server/location_main.c @@ -322,7 +322,7 @@ static UINT location_process_message(location_server* location) wStream* s = location->buffer; WINPR_ASSERT(s); - Stream_SetPosition(s, 0); + Stream_ResetPosition(s); const BOOL rc = WTSVirtualChannelRead(location->location_channel, 0, nullptr, 0, &BytesReturned); if (!rc) diff --git a/channels/printer/client/printer_main.c b/channels/printer/client/printer_main.c index 77eb5c5c7..a2b286707 100644 --- a/channels/printer/client/printer_main.c +++ b/channels/printer/client/printer_main.c @@ -380,7 +380,7 @@ static BOOL printer_load_from_config(const rdpSettings* settings, rdpPrinter* pr { } - Stream_SetPosition(printer_dev->device.data, 0); + Stream_ResetPosition(printer_dev->device.data); if (!Stream_EnsureRemainingCapacity(printer_dev->device.data, 24)) goto fail; diff --git a/channels/rail/client/rail_orders.c b/channels/rail/client/rail_orders.c index 7aa50922e..4f43077c8 100644 --- a/channels/rail/client/rail_orders.c +++ b/channels/rail/client/rail_orders.c @@ -51,7 +51,7 @@ UINT rail_send_pdu(railPlugin* rail, wStream* s, UINT16 orderType) } orderLength = (UINT16)Stream_GetPosition(s); - Stream_SetPosition(s, 0); + Stream_ResetPosition(s); rail_write_pdu_header(s, orderType, orderLength); Stream_SetPosition(s, orderLength); WLog_Print(rail->log, WLOG_DEBUG, "Sending %s PDU, length: %" PRIu16 "", diff --git a/channels/rail/server/rail_main.c b/channels/rail/server/rail_main.c index 2729bc6d8..686427f32 100644 --- a/channels/rail/server/rail_main.c +++ b/channels/rail/server/rail_main.c @@ -70,7 +70,7 @@ static UINT rail_server_send_pdu(RailServerContext* context, wStream* s, UINT16 return ERROR_INVALID_PARAMETER; orderLength = (UINT16)Stream_GetPosition(s); - Stream_SetPosition(s, 0); + Stream_ResetPosition(s); rail_write_pdu_header(s, orderType, orderLength); Stream_SetPosition(s, orderLength); WLog_DBG(TAG, "Sending %s PDU, length: %" PRIu16 "", diff --git a/channels/rdpdr/client/rdpdr_main.c b/channels/rdpdr/client/rdpdr_main.c index 861a01454..7b51f6c47 100644 --- a/channels/rdpdr/client/rdpdr_main.c +++ b/channels/rdpdr/client/rdpdr_main.c @@ -2017,7 +2017,7 @@ static UINT rdpdr_virtual_channel_event_data_received(rdpdrPlugin* rdpdr, void* } Stream_SealLength(data_in); - Stream_SetPosition(data_in, 0); + Stream_ResetPosition(data_in); if (rdpdr->async) { diff --git a/channels/rdpdr/server/rdpdr_main.c b/channels/rdpdr/server/rdpdr_main.c index a5e0d3786..23b5d8763 100644 --- a/channels/rdpdr/server/rdpdr_main.c +++ b/channels/rdpdr/server/rdpdr_main.c @@ -277,7 +277,7 @@ static UINT rdpdr_seal_send_free_request(RdpdrServerContext* context, wStream* s Stream_SealLength(s); const size_t length = Stream_Length(s); WINPR_ASSERT(length <= UINT32_MAX); - Stream_SetPosition(s, 0); + Stream_ResetPosition(s); if (length >= RDPDR_HEADER_LENGTH) { @@ -2249,7 +2249,7 @@ static DWORD WINAPI rdpdr_server_thread(LPVOID arg) if (BytesReturned >= RDPDR_HEADER_LENGTH) { - Stream_SetPosition(s, 0); + Stream_ResetPosition(s); Stream_SetLength(s, BytesReturned); while (Stream_GetRemainingLength(s) >= RDPDR_HEADER_LENGTH) diff --git a/channels/rdpecam/client/camera_device_main.c b/channels/rdpecam/client/camera_device_main.c index 033b1a962..9bc6740e6 100644 --- a/channels/rdpecam/client/camera_device_main.c +++ b/channels/rdpecam/client/camera_device_main.c @@ -105,7 +105,7 @@ static UINT ecam_dev_send_sample_response(CameraDevice* dev, size_t streamIndex, CameraDeviceStream* stream = &dev->streams[streamIndex]; CAM_MSG_ID msg = CAM_MSG_ID_SampleResponse; - Stream_SetPosition(stream->sampleRespBuffer, 0); + Stream_ResetPosition(stream->sampleRespBuffer); Stream_Write_UINT8(stream->sampleRespBuffer, WINPR_ASSERTING_INT_CAST(uint8_t, dev->ecam->version)); @@ -229,7 +229,7 @@ static UINT ecam_dev_sample_captured_callback(CameraDevice* dev, size_t streamIn } } - Stream_SetPosition(stream->pendingSample, 0); + Stream_ResetPosition(stream->pendingSample); if (!Stream_EnsureRemainingCapacity(stream->pendingSample, size)) goto out; diff --git a/channels/rdpecam/server/camera_device_enumerator_main.c b/channels/rdpecam/server/camera_device_enumerator_main.c index 8c0dda54b..da005a1bd 100644 --- a/channels/rdpecam/server/camera_device_enumerator_main.c +++ b/channels/rdpecam/server/camera_device_enumerator_main.c @@ -273,7 +273,7 @@ static UINT enumerator_process_message(enumerator_server* enumerator) s = enumerator->buffer; WINPR_ASSERT(s); - Stream_SetPosition(s, 0); + Stream_ResetPosition(s); rc = WTSVirtualChannelRead(enumerator->enumerator_channel, 0, nullptr, 0, &BytesReturned); if (!rc) goto out; diff --git a/channels/rdpecam/server/camera_device_main.c b/channels/rdpecam/server/camera_device_main.c index 7d1d5de12..d2112860b 100644 --- a/channels/rdpecam/server/camera_device_main.c +++ b/channels/rdpecam/server/camera_device_main.c @@ -479,7 +479,7 @@ static UINT device_process_message(device_server* device) s = device->buffer; WINPR_ASSERT(s); - Stream_SetPosition(s, 0); + Stream_ResetPosition(s); rc = WTSVirtualChannelRead(device->device_channel, 0, nullptr, 0, &BytesReturned); if (!rc) goto out; diff --git a/channels/rdpei/client/rdpei_main.c b/channels/rdpei/client/rdpei_main.c index 502b9d643..10d005964 100644 --- a/channels/rdpei/client/rdpei_main.c +++ b/channels/rdpei/client/rdpei_main.c @@ -230,7 +230,7 @@ static UINT rdpei_send_pdu(GENERIC_CHANNEL_CALLBACK* callback, wStream* s, UINT1 if (!rdpei) return ERROR_INTERNAL_ERROR; - Stream_SetPosition(s, 0); + Stream_ResetPosition(s); Stream_Write_UINT16(s, eventId); /* eventId (2 bytes) */ Stream_Write_UINT32(s, (UINT32)pduLength); /* pduLength (4 bytes) */ Stream_SetPosition(s, Stream_Length(s)); diff --git a/channels/rdpei/server/rdpei_main.c b/channels/rdpei/server/rdpei_main.c index 91d2c5057..34ae6c5b3 100644 --- a/channels/rdpei/server/rdpei_main.c +++ b/channels/rdpei/server/rdpei_main.c @@ -345,7 +345,7 @@ void rdpei_server_context_reset(RdpeiServerContext* context) priv->expectedBytes = RDPINPUT_HEADER_LENGTH; priv->waitingHeaders = TRUE; priv->automataState = STATE_INITIAL; - Stream_SetPosition(priv->inputStream, 0); + Stream_ResetPosition(priv->inputStream); } void rdpei_server_context_free(RdpeiServerContext* context) @@ -709,7 +709,7 @@ UINT rdpei_server_handle_messages(RdpeiServerContext* context) return CHANNEL_RC_OK; Stream_SealLength(s); - Stream_SetPosition(s, 0); + Stream_ResetPosition(s); if (priv->waitingHeaders) { @@ -726,7 +726,7 @@ UINT rdpei_server_handle_messages(RdpeiServerContext* context) } priv->expectedBytes = pduLen - RDPINPUT_HEADER_LENGTH; priv->waitingHeaders = FALSE; - Stream_SetPosition(s, 0); + Stream_ResetPosition(s); if (priv->expectedBytes) { if (!Stream_EnsureCapacity(s, priv->expectedBytes)) @@ -781,7 +781,7 @@ UINT rdpei_server_handle_messages(RdpeiServerContext* context) WLog_ERR(TAG, "unexpected message type 0x%" PRIx16 "", priv->currentMsgType); } - Stream_SetPosition(s, 0); + Stream_ResetPosition(s); priv->waitingHeaders = TRUE; priv->expectedBytes = RDPINPUT_HEADER_LENGTH; return error; @@ -804,7 +804,7 @@ UINT rdpei_server_send_sc_ready(RdpeiServerContext* context, UINT32 version, UIN return ERROR_INVALID_STATE; } - Stream_SetPosition(priv->outputStream, 0); + Stream_ResetPosition(priv->outputStream); if (version >= RDPINPUT_PROTOCOL_V300) pduLen += 4; @@ -857,7 +857,7 @@ UINT rdpei_server_suspend(RdpeiServerContext* context) return ERROR_INVALID_STATE; } - Stream_SetPosition(priv->outputStream, 0); + Stream_ResetPosition(priv->outputStream); if (!Stream_EnsureCapacity(priv->outputStream, RDPINPUT_HEADER_LENGTH)) { WLog_ERR(TAG, "Stream_EnsureCapacity failed!"); @@ -903,7 +903,7 @@ UINT rdpei_server_resume(RdpeiServerContext* context) return ERROR_INVALID_STATE; } - Stream_SetPosition(priv->outputStream, 0); + Stream_ResetPosition(priv->outputStream); if (!Stream_EnsureCapacity(priv->outputStream, RDPINPUT_HEADER_LENGTH)) { WLog_ERR(TAG, "Stream_EnsureCapacity failed!"); diff --git a/channels/rdpemsc/server/mouse_cursor_main.c b/channels/rdpemsc/server/mouse_cursor_main.c index c036c1a87..6dcbef654 100644 --- a/channels/rdpemsc/server/mouse_cursor_main.c +++ b/channels/rdpemsc/server/mouse_cursor_main.c @@ -246,7 +246,7 @@ static UINT mouse_cursor_process_message(mouse_cursor_server* mouse_cursor) s = mouse_cursor->buffer; WINPR_ASSERT(s); - Stream_SetPosition(s, 0); + Stream_ResetPosition(s); rc = WTSVirtualChannelRead(mouse_cursor->mouse_cursor_channel, 0, nullptr, 0, &BytesReturned); if (!rc) goto out; diff --git a/channels/rdpgfx/server/rdpgfx_main.c b/channels/rdpgfx/server/rdpgfx_main.c index cbb239e9f..26068cb06 100644 --- a/channels/rdpgfx/server/rdpgfx_main.c +++ b/channels/rdpgfx/server/rdpgfx_main.c @@ -1839,7 +1839,7 @@ UINT rdpgfx_server_handle_messages(RdpgfxServerContext* context) /* Consume channel event only after the gfx dynamic channel is ready */ if (priv->isReady) { - Stream_SetPosition(s, 0); + Stream_ResetPosition(s); if (!WTSVirtualChannelRead(priv->rdpgfx_channel, 0, nullptr, 0, &BytesReturned)) { @@ -1870,7 +1870,7 @@ UINT rdpgfx_server_handle_messages(RdpgfxServerContext* context) } Stream_SetLength(s, BytesReturned); - Stream_SetPosition(s, 0); + Stream_ResetPosition(s); while (Stream_GetPosition(s) < Stream_Length(s)) { diff --git a/channels/rdpsnd/client/rdpsnd_main.c b/channels/rdpsnd/client/rdpsnd_main.c index 6cab3cbaa..c140acfed 100644 --- a/channels/rdpsnd/client/rdpsnd_main.c +++ b/channels/rdpsnd/client/rdpsnd_main.c @@ -1163,7 +1163,7 @@ static UINT rdpsnd_virtual_channel_event_data_received(rdpsndPlugin* plugin, voi if (!plugin->data_in) plugin->data_in = StreamPool_Take(plugin->pool, totalLength); - Stream_SetPosition(plugin->data_in, 0); + Stream_ResetPosition(plugin->data_in); } if (!Stream_EnsureRemainingCapacity(plugin->data_in, dataLength)) @@ -1174,7 +1174,7 @@ static UINT rdpsnd_virtual_channel_event_data_received(rdpsndPlugin* plugin, voi if (dataFlags & CHANNEL_FLAG_LAST) { Stream_SealLength(plugin->data_in); - Stream_SetPosition(plugin->data_in, 0); + Stream_ResetPosition(plugin->data_in); if (plugin->async) { @@ -1677,7 +1677,7 @@ static UINT rdpsnd_on_data_received(IWTSVirtualChannelCallback* pChannelCallback return ERROR_OUTOFMEMORY; Stream_Copy(data, copy, len); Stream_SealLength(copy); - Stream_SetPosition(copy, 0); + Stream_ResetPosition(copy); if (plugin->async) { diff --git a/channels/rdpsnd/server/rdpsnd_main.c b/channels/rdpsnd/server/rdpsnd_main.c index 108cd9913..79a48cb4b 100644 --- a/channels/rdpsnd/server/rdpsnd_main.c +++ b/channels/rdpsnd/server/rdpsnd_main.c @@ -44,7 +44,7 @@ static wStream* rdpsnd_server_get_buffer(RdpsndServerContext* context) WINPR_ASSERT(context->priv); s = context->priv->rdpsnd_pdu; - Stream_SetPosition(s, 0); + Stream_ResetPosition(s); return s; } @@ -97,7 +97,7 @@ static UINT rdpsnd_server_send_formats(RdpsndServerContext* context) status = WTSVirtualChannelWrite(context->priv->ChannelHandle, Stream_BufferAs(s, char), (UINT32)pos, &written); - Stream_SetPosition(s, 0); + Stream_ResetPosition(s); } fail: return status ? CHANNEL_RC_OK : ERROR_INTERNAL_ERROR; @@ -446,7 +446,7 @@ static UINT rdpsnd_server_training(RdpsndServerContext* context, UINT16 timestam { if (!Stream_EnsureRemainingCapacity(s, packsize)) { - Stream_SetPosition(s, 0); + Stream_ResetPosition(s); return ERROR_INTERNAL_ERROR; } @@ -463,7 +463,7 @@ static UINT rdpsnd_server_training(RdpsndServerContext* context, UINT16 timestam status = WTSVirtualChannelWrite(context->priv->ChannelHandle, Stream_BufferAs(s, char), (UINT32)end, &written); - Stream_SetPosition(s, 0); + Stream_ResetPosition(s); return status ? CHANNEL_RC_OK : ERROR_INTERNAL_ERROR; } @@ -508,7 +508,7 @@ static UINT rdpsnd_server_send_wave_pdu(RdpsndServerContext* context, UINT16 wTi format = &context->client_formats[context->selected_client_format]; /* WaveInfo PDU */ - Stream_SetPosition(s, 0); + Stream_ResetPosition(s); if (!Stream_EnsureRemainingCapacity(s, 16)) return ERROR_OUTOFMEMORY; @@ -569,7 +569,7 @@ static UINT rdpsnd_server_send_wave_pdu(RdpsndServerContext* context, UINT16 wTi context->block_no = (context->block_no + 1) % 256; out: - Stream_SetPosition(s, 0); + Stream_ResetPosition(s); context->priv->out_pending_frames = 0; return error; } @@ -661,7 +661,7 @@ static UINT rdpsnd_server_send_wave2_pdu(RdpsndServerContext* context, UINT16 fo context->block_no = (context->block_no + 1) % 256; out: - Stream_SetPosition(s, 0); + Stream_ResetPosition(s); context->priv->out_pending_frames = 0; return error; } @@ -789,7 +789,7 @@ static UINT rdpsnd_server_set_volume(RdpsndServerContext* context, UINT16 left, WINPR_ASSERT(len <= UINT32_MAX); status = WTSVirtualChannelWrite(context->priv->ChannelHandle, Stream_BufferAs(s, char), (ULONG)len, &written); - Stream_SetPosition(s, 0); + Stream_ResetPosition(s); return status ? CHANNEL_RC_OK : ERROR_INTERNAL_ERROR; } @@ -843,7 +843,7 @@ static UINT rdpsnd_server_close(RdpsndServerContext* context) WINPR_ASSERT(len <= UINT32_MAX); status = WTSVirtualChannelWrite(context->priv->ChannelHandle, Stream_BufferAs(s, char), (UINT32)len, &written); - Stream_SetPosition(s, 0); + Stream_ResetPosition(s); return status ? CHANNEL_RC_OK : ERROR_INTERNAL_ERROR; } @@ -1178,7 +1178,7 @@ UINT rdpsnd_server_handle_messages(RdpsndServerContext* context) return CHANNEL_RC_OK; Stream_SealLength(s); - Stream_SetPosition(s, 0); + Stream_ResetPosition(s); if (priv->waitingHeader) { @@ -1187,7 +1187,7 @@ UINT rdpsnd_server_handle_messages(RdpsndServerContext* context) Stream_Seek_UINT8(s); /* bPad */ Stream_Read_UINT16(s, priv->expectedBytes); priv->waitingHeader = FALSE; - Stream_SetPosition(s, 0); + Stream_ResetPosition(s); if (priv->expectedBytes) { @@ -1240,6 +1240,6 @@ UINT rdpsnd_server_handle_messages(RdpsndServerContext* context) break; } - Stream_SetPosition(s, 0); + Stream_ResetPosition(s); return ret; } diff --git a/channels/remdesk/client/remdesk_main.c b/channels/remdesk/client/remdesk_main.c index 9115fa0f5..32d881d05 100644 --- a/channels/remdesk/client/remdesk_main.c +++ b/channels/remdesk/client/remdesk_main.c @@ -725,7 +725,7 @@ static UINT remdesk_virtual_channel_event_data_received(remdeskPlugin* remdesk, remdesk->data_in = nullptr; Stream_SealLength(data_in); - Stream_SetPosition(data_in, 0); + Stream_ResetPosition(data_in); if (!MessageQueue_Post(remdesk->queue, nullptr, 0, (void*)data_in, nullptr)) { diff --git a/channels/remdesk/server/remdesk_main.c b/channels/remdesk/server/remdesk_main.c index 8782b32a1..3988474b5 100644 --- a/channels/remdesk/server/remdesk_main.c +++ b/channels/remdesk/server/remdesk_main.c @@ -524,7 +524,7 @@ static DWORD WINAPI remdesk_server_thread(LPVOID arg) if (PduLength >= Stream_GetPosition(s)) { Stream_SealLength(s); - Stream_SetPosition(s, 0); + Stream_ResetPosition(s); error = remdesk_server_receive_pdu(context, s); if (error) @@ -534,7 +534,7 @@ static DWORD WINAPI remdesk_server_thread(LPVOID arg) break; } - Stream_SetPosition(s, 0); + Stream_ResetPosition(s); } } } diff --git a/channels/telemetry/server/telemetry_main.c b/channels/telemetry/server/telemetry_main.c index 91c89bea4..59c6f86ed 100644 --- a/channels/telemetry/server/telemetry_main.c +++ b/channels/telemetry/server/telemetry_main.c @@ -156,7 +156,7 @@ static UINT telemetry_process_message(telemetry_server* telemetry) s = telemetry->buffer; WINPR_ASSERT(s); - Stream_SetPosition(s, 0); + Stream_ResetPosition(s); rc = WTSVirtualChannelRead(telemetry->telemetry_channel, 0, nullptr, 0, &BytesReturned); if (!rc) goto out; diff --git a/channels/tsmf/client/tsmf_main.c b/channels/tsmf/client/tsmf_main.c index 481691e0e..85ad53088 100644 --- a/channels/tsmf/client/tsmf_main.c +++ b/channels/tsmf/client/tsmf_main.c @@ -380,7 +380,7 @@ static UINT tsmf_on_data_received(IWTSVirtualChannelCallback* pChannelCallback, const size_t length = Stream_GetPosition(output); if (length > UINT32_MAX) goto out; - Stream_SetPosition(output, 0); + Stream_ResetPosition(output); Stream_Write_UINT32(output, ifman.output_interface_id); Stream_Write_UINT32(output, MessageId); DEBUG_TSMF("response size %d", length); diff --git a/channels/urbdrc/client/data_transfer.c b/channels/urbdrc/client/data_transfer.c index 89350ad99..55eae271c 100644 --- a/channels/urbdrc/client/data_transfer.c +++ b/channels/urbdrc/client/data_transfer.c @@ -111,7 +111,7 @@ static UINT urb_write_completion(WINPR_ATTR_UNUSED IUDEVICE* pdev, return ERROR_INVALID_PARAMETER; } - Stream_SetPosition(out, 0); + Stream_ResetPosition(out); const UINT32 FunctionId = (OutputBufferSize != 0) ? URB_COMPLETION : URB_COMPLETION_NO_DATA; if (!write_shared_message_header_with_functionid(out, InterfaceId, MessageId, FunctionId)) @@ -854,7 +854,7 @@ static void urb_isoch_transfer_cb(WINPR_ATTR_UNUSED IUDEVICE* pdev, if (!noAck) { UINT32 packetSize = (status == 0) ? NumberOfPackets * 12 : 0; - Stream_SetPosition(out, 0); + Stream_ResetPosition(out); const UINT32 FunctionId = (OutputBufferSize == 0) ? URB_COMPLETION_NO_DATA : URB_COMPLETION; if (!write_shared_message_header_with_functionid(out, InterfaceId, MessageId, FunctionId)) diff --git a/channels/urbdrc/common/urbdrc_helpers.c b/channels/urbdrc/common/urbdrc_helpers.c index 85dbe7950..7730a7f98 100644 --- a/channels/urbdrc/common/urbdrc_helpers.c +++ b/channels/urbdrc/common/urbdrc_helpers.c @@ -398,7 +398,7 @@ void urbdrc_dump_message(wLog* log, BOOL client, BOOL write, wStream* s) if (write) { length = pos; - Stream_SetPosition(s, 0); + Stream_ResetPosition(s); } else length = Stream_GetRemainingLength(s); diff --git a/channels/video/client/video_main.c b/channels/video/client/video_main.c index ef9718846..0dc046f2b 100644 --- a/channels/video/client/video_main.c +++ b/channels/video/client/video_main.c @@ -661,7 +661,7 @@ static UINT video_control_send_client_notification(VideoClientContext* context, } Stream_SealLength(s); - Stream_SetPosition(s, 0); + Stream_ResetPosition(s); Stream_Write_UINT32(s, cbSize); Stream_Free(s, FALSE); @@ -846,7 +846,7 @@ static UINT video_VideoData(VideoClientContext* context, const TSMM_VIDEO_DATA* const RECTANGLE_16 rect = { 0, 0, WINPR_ASSERTING_INT_CAST(UINT16, surface->alignedWidth), WINPR_ASSERTING_INT_CAST(UINT16, surface->alignedHeight) }; Stream_SealLength(presentation->currentSample); - Stream_SetPosition(presentation->currentSample, 0); + Stream_ResetPosition(presentation->currentSample); const UINT64 timeAfterH264 = winpr_GetTickCount64NS(); if (data->SampleNumber == 1) diff --git a/libfreerdp/codec/bitmap.c b/libfreerdp/codec/bitmap.c index 31a91f027..0857773d6 100644 --- a/libfreerdp/codec/bitmap.c +++ b/libfreerdp/codec/bitmap.c @@ -171,7 +171,7 @@ static inline UINT16 out_copy_count_2(UINT16 in_count, wStream* WINPR_RESTRICT i Stream_Write(in_s, Stream_Buffer(in_data), 2ULL * in_count); } - Stream_SetPosition(in_data, 0); + Stream_ResetPosition(in_data); return 0; } @@ -202,7 +202,7 @@ static inline UINT16 out_copy_count_3(UINT16 in_count, wStream* WINPR_RESTRICT i Stream_Write(in_s, Stream_Pointer(in_data), 3ULL * in_count); } - Stream_SetPosition(in_data, 0); + Stream_ResetPosition(in_data); return 0; } @@ -696,7 +696,7 @@ static inline SSIZE_T freerdp_bitmap_compress_24(const void* WINPR_RESTRICT srcD lines_sent++; } - Stream_SetPosition(temp_s, 0); + Stream_ResetPosition(temp_s); if (counts.fill_count > 3 && counts.fill_count >= counts.color_count && counts.fill_count >= counts.bicolor_count && counts.fill_count >= counts.mix_count && @@ -1017,7 +1017,7 @@ static inline SSIZE_T freerdp_bitmap_compress_16(const void* WINPR_RESTRICT srcD lines_sent++; } - Stream_SetPosition(temp_s, 0); + Stream_ResetPosition(temp_s); if (counts.fill_count > 3 && counts.fill_count >= counts.color_count && counts.fill_count >= counts.bicolor_count && counts.fill_count >= counts.mix_count && @@ -1096,7 +1096,7 @@ SSIZE_T freerdp_bitmap_compress(const void* WINPR_RESTRICT srcData, UINT32 width wStream* WINPR_RESTRICT s, UINT32 bpp, UINT32 byte_limit, UINT32 start_line, wStream* WINPR_RESTRICT temp_s, UINT32 e) { - Stream_SetPosition(temp_s, 0); + Stream_ResetPosition(temp_s); switch (bpp) { diff --git a/libfreerdp/codec/dsp.c b/libfreerdp/codec/dsp.c index 8ba3d502d..bf6c63f61 100644 --- a/libfreerdp/codec/dsp.c +++ b/libfreerdp/codec/dsp.c @@ -166,7 +166,7 @@ static BOOL freerdp_dsp_channel_mix(FREERDP_DSP_CONTEXT* WINPR_RESTRICT context, return TRUE; } - Stream_SetPosition(context->common.channelmix, 0); + Stream_ResetPosition(context->common.channelmix); /* Destination has more channels than source */ if (context->common.format.nChannels > srcFormat->nChannels) @@ -600,7 +600,7 @@ static BOOL freerdp_dsp_encode_faac(FREERDP_DSP_CONTEXT* WINPR_RESTRICT context, return FALSE; if (rc > 0) Stream_Seek(out, (size_t)rc); - Stream_SetPosition(context->common.buffer, 0); + Stream_ResetPosition(context->common.buffer); } } @@ -870,7 +870,7 @@ static BOOL freerdp_dsp_encode_ima_adpcm(FREERDP_DSP_CONTEXT* WINPR_RESTRICT con { BYTE* bsrc = Stream_Buffer(context->common.buffer); Stream_Write(out, bsrc, context->adpcm.ima.packet_size); - Stream_SetPosition(context->common.buffer, 0); + Stream_ResetPosition(context->common.buffer); } } @@ -1499,7 +1499,7 @@ BOOL freerdp_dsp_context_reset(FREERDP_DSP_CONTEXT* WINPR_RESTRICT context, context->adpcm.ima.packet_size = nb_block_per_packet * context->common.format.nBlockAlign; Stream_EnsureCapacity(context->common.buffer, context->adpcm.ima.packet_size); - Stream_SetPosition(context->common.buffer, 0); + Stream_ResetPosition(context->common.buffer); } #if defined(WITH_OPUS) diff --git a/libfreerdp/codec/dsp_ffmpeg.c b/libfreerdp/codec/dsp_ffmpeg.c index 98f74db48..447cce4e4 100644 --- a/libfreerdp/codec/dsp_ffmpeg.c +++ b/libfreerdp/codec/dsp_ffmpeg.c @@ -738,7 +738,7 @@ static BOOL freerdp_dsp_channel_mix(FREERDP_DSP_CONTEXT* WINPR_RESTRICT context, return TRUE; } - Stream_SetPosition(context->common.channelmix, 0); + Stream_ResetPosition(context->common.channelmix); /* Destination has more channels than source */ if (context->common.format.nChannels > srcFormat->nChannels) diff --git a/libfreerdp/codec/interleaved.c b/libfreerdp/codec/interleaved.c index ec0a6fcf1..1dddda92a 100644 --- a/libfreerdp/codec/interleaved.c +++ b/libfreerdp/codec/interleaved.c @@ -698,7 +698,7 @@ BOOL interleaved_compress(BITMAP_INTERLEAVED_CONTEXT* WINPR_RESTRICT interleaved if (!s) return FALSE; - Stream_SetPosition(interleaved->bts, 0); + Stream_ResetPosition(interleaved->bts); status = (freerdp_bitmap_compress(interleaved->TempBuffer, nWidth, nHeight, s, bpp, maxSize, nHeight - 1, interleaved->bts, 0) >= 0); diff --git a/libfreerdp/codec/progressive.c b/libfreerdp/codec/progressive.c index 5e52f7cb1..fc0b6dbbe 100644 --- a/libfreerdp/codec/progressive.c +++ b/libfreerdp/codec/progressive.c @@ -2554,7 +2554,7 @@ int progressive_compress(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive, } } s = progressive->buffer; - Stream_SetPosition(s, 0); + Stream_ResetPosition(s); progressive->rfx_context->mode = RLGR1; diff --git a/libfreerdp/core/fastpath.c b/libfreerdp/core/fastpath.c index 1cba90c92..801098af7 100644 --- a/libfreerdp/core/fastpath.c +++ b/libfreerdp/core/fastpath.c @@ -354,7 +354,7 @@ static int fastpath_recv_update(rdpFastPath* fastpath, BYTE updateCode, wStream* return -1; Stream_SealLength(s); - Stream_SetPosition(s, 0); + Stream_ResetPosition(s); rdpUpdate* update = fastpath->rdp->update; @@ -478,7 +478,7 @@ static int fastpath_recv_update(rdpFastPath* fastpath, BYTE updateCode, wStream* break; } - Stream_SetPosition(s, 0); + Stream_ResetPosition(s); if (!rc) { WLog_ERR(TAG, "Fastpath update %s [%" PRIx8 "] failed, status %d", @@ -1063,7 +1063,7 @@ BOOL fastpath_send_multiple_input_pdu(rdpFastPath* fastpath, wStream* s, size_t if (sec_flags & SEC_SECURE_CHECKSUM) eventHeader |= (FASTPATH_INPUT_SECURE_CHECKSUM << 6); - Stream_SetPosition(s, 0); + Stream_ResetPosition(s); Stream_Write_UINT8(s, eventHeader); /* Write length later, RDP encryption might add a padding */ Stream_Seek(s, 2); @@ -1199,7 +1199,7 @@ BOOL fastpath_send_update_pdu(rdpFastPath* fastpath, BYTE updateCode, wStream* s } size_t totalLength = Stream_GetPosition(s); - Stream_SetPosition(s, 0); + Stream_ResetPosition(s); /* check if fast path output is possible */ if (!settings->FastPathOutput) @@ -1308,7 +1308,7 @@ BOOL fastpath_send_update_pdu(rdpFastPath* fastpath, BYTE updateCode, wStream* s return FALSE; fpUpdatePduHeader.length = (UINT16)len; - Stream_SetPosition(fs, 0); + Stream_ResetPosition(fs); if (!fastpath_write_update_pdu_header(fs, &fpUpdatePduHeader, rdp)) return FALSE; if (!fastpath_write_update_header(fs, &fpUpdateHeader)) diff --git a/libfreerdp/core/freerdp.c b/libfreerdp/core/freerdp.c index 26e9d5004..723625b78 100644 --- a/libfreerdp/core/freerdp.c +++ b/libfreerdp/core/freerdp.c @@ -269,7 +269,7 @@ BOOL freerdp_connect(freerdp* instance) if (!pcap_get_next_record_content(update->pcap_rfx, &record)) break; Stream_SetLength(s, record.length); - Stream_SetPosition(s, 0); + Stream_ResetPosition(s); if (!update_begin_paint(&update->common)) status = FALSE; diff --git a/libfreerdp/core/gateway/rdg.c b/libfreerdp/core/gateway/rdg.c index 832ebba0d..53d831f7f 100644 --- a/libfreerdp/core/gateway/rdg.c +++ b/libfreerdp/core/gateway/rdg.c @@ -1134,7 +1134,7 @@ static BOOL rdg_process_packet(rdpRdg* rdg, wStream* s) BOOL status = TRUE; UINT16 type = 0; UINT32 packetLength = 0; - Stream_SetPosition(s, 0); + Stream_ResetPosition(s); if (!Stream_CheckAndLogRequiredLengthWLog(rdg->log, s, 8)) return FALSE; @@ -1901,7 +1901,7 @@ static BOOL rdg_process_control_packet(rdpRdg* rdg, int type, size_t packetLengt } } - Stream_SetPosition(s, 0); + Stream_ResetPosition(s); } switch (type) diff --git a/libfreerdp/core/gateway/rpc_client.c b/libfreerdp/core/gateway/rpc_client.c index 384ef47ab..543740901 100644 --- a/libfreerdp/core/gateway/rpc_client.c +++ b/libfreerdp/core/gateway/rpc_client.c @@ -93,7 +93,7 @@ static void rpc_pdu_reset(RPC_PDU* pdu) pdu->Type = 0; pdu->Flags = 0; pdu->CallId = 0; - Stream_SetPosition(pdu->s, 0); + Stream_ResetPosition(pdu->s); Stream_SetLength(pdu->s, 0); } @@ -346,7 +346,7 @@ static int rpc_client_recv_pdu(rdpRpc* rpc, RPC_PDU* pdu) WINPR_ASSERT(pdu); Stream_SealLength(pdu->s); - Stream_SetPosition(pdu->s, 0); + Stream_ResetPosition(pdu->s); const size_t before = Stream_GetRemainingLength(pdu->s); WLog_Print(rpc->log, WLOG_TRACE, "RPC PDU parsing %" PRIuz " bytes", before); @@ -381,7 +381,7 @@ static int rpc_client_recv_fragment(rdpRpc* rpc, wStream* fragment) WINPR_ASSERT(pdu); Stream_SealLength(fragment); - Stream_SetPosition(fragment, 0); + Stream_ResetPosition(fragment); if (!rts_read_pdu_header(fragment, &header)) goto fail; @@ -689,7 +689,7 @@ static SSIZE_T rpc_client_default_out_channel_recv(rdpRpc* rpc) } pos = Stream_GetPosition(fragment); - Stream_SetPosition(fragment, 0); + Stream_ResetPosition(fragment); /* Ignore errors, the PDU might not be complete. */ const rts_pdu_status_t rc = rts_read_common_pdu_header(fragment, &header, TRUE); @@ -744,7 +744,7 @@ static SSIZE_T rpc_client_default_out_channel_recv(rdpRpc* rpc) return 0; } - Stream_SetPosition(fragment, 0); + Stream_ResetPosition(fragment); } } } diff --git a/libfreerdp/core/gateway/websocket.c b/libfreerdp/core/gateway/websocket.c index 535e682b8..f79f92c55 100644 --- a/libfreerdp/core/gateway/websocket.c +++ b/libfreerdp/core/gateway/websocket.c @@ -42,7 +42,7 @@ BOOL websocket_context_mask_and_send(BIO* bio, wStream* sPacket, wStream* sDataP UINT32 maskingKey) { const size_t len = Stream_Length(sDataPacket); - Stream_SetPosition(sDataPacket, 0); + Stream_ResetPosition(sDataPacket); if (!Stream_EnsureRemainingCapacity(sPacket, len)) return FALSE; @@ -308,7 +308,7 @@ static int websocket_handle_payload(BIO* bio, BYTE* pBuffer, size_t size, if (encodingContext->payloadLength == 0) { websocket_reply_pong(bio, encodingContext, encodingContext->responseStreamBuffer); - Stream_SetPosition(encodingContext->responseStreamBuffer, 0); + Stream_ResetPosition(encodingContext->responseStreamBuffer); } } break; @@ -318,7 +318,7 @@ static int websocket_handle_payload(BIO* bio, BYTE* pBuffer, size_t size, if (status < 0) return status; /* We don“t care about pong response data, discard. */ - Stream_SetPosition(encodingContext->responseStreamBuffer, 0); + Stream_ResetPosition(encodingContext->responseStreamBuffer); } break; case WebsocketCloseOpcode: @@ -331,7 +331,7 @@ static int websocket_handle_payload(BIO* bio, BYTE* pBuffer, size_t size, { websocket_reply_close(bio, encodingContext, encodingContext->responseStreamBuffer); encodingContext->closeSent = TRUE; - Stream_SetPosition(encodingContext->responseStreamBuffer, 0); + Stream_ResetPosition(encodingContext->responseStreamBuffer); } } break; @@ -341,7 +341,7 @@ static int websocket_handle_payload(BIO* bio, BYTE* pBuffer, size_t size, status = websocket_read_wstream(bio, encodingContext); if (status < 0) return status; - Stream_SetPosition(encodingContext->responseStreamBuffer, 0); + Stream_ResetPosition(encodingContext->responseStreamBuffer); break; } /* return how many bytes have been written to pBuffer. diff --git a/libfreerdp/core/message.c b/libfreerdp/core/message.c index 172bfcd64..1d61fd333 100644 --- a/libfreerdp/core/message.c +++ b/libfreerdp/core/message.c @@ -256,7 +256,7 @@ static BOOL update_message_SurfaceCommand(rdpContext* context, wStream* s) return FALSE; Stream_Copy(s, wParam, Stream_GetRemainingLength(s)); - Stream_SetPosition(wParam, 0); + Stream_ResetPosition(wParam); up = update_cast(context->update); return MessageQueue_Post(up->queue, (void*)context, MakeMessageId(Update, SurfaceCommand), diff --git a/libfreerdp/core/nla.c b/libfreerdp/core/nla.c index ff82ecc79..fd392034d 100644 --- a/libfreerdp/core/nla.c +++ b/libfreerdp/core/nla.c @@ -640,7 +640,7 @@ static int nla_client_authenticate(rdpNla* nla) while (nla_get_state(nla) < NLA_STATE_AUTH_INFO) { - Stream_SetPosition(s, 0); + Stream_ResetPosition(s); const int status = transport_read_pdu(nla->transport, s); if (status < 0) diff --git a/libfreerdp/core/rdp.c b/libfreerdp/core/rdp.c index d777c5971..2f3549e1c 100644 --- a/libfreerdp/core/rdp.c +++ b/libfreerdp/core/rdp.c @@ -841,7 +841,7 @@ BOOL rdp_send(rdpRdp* rdp, wStream* s, UINT16 channelId, UINT16 sec_flags) { size_t length = Stream_GetPosition(s); - Stream_SetPosition(s, 0); + Stream_ResetPosition(s); if (!rdp_write_header(rdp, s, length, channelId, sec_flags)) goto fail; @@ -886,7 +886,7 @@ BOOL rdp_send_pdu(rdpRdp* rdp, wStream* s, UINT16 type, UINT16 channel_id, UINT1 { size_t length = Stream_GetPosition(s); - Stream_SetPosition(s, 0); + Stream_ResetPosition(s); if (!rdp_write_header(rdp, s, length, MCS_GLOBAL_CHANNEL_ID, sec_flags)) goto fail; sec_bytes = rdp_get_sec_bytes(rdp, sec_flags); @@ -936,7 +936,7 @@ BOOL rdp_send_data_pdu(rdpRdp* rdp, wStream* s, BYTE type, UINT16 channel_id, UI { size_t length = Stream_GetPosition(s); - Stream_SetPosition(s, 0); + Stream_ResetPosition(s); if (!rdp_write_header(rdp, s, length, MCS_GLOBAL_CHANNEL_ID, sec_flags)) goto fail; sec_bytes = rdp_get_sec_bytes(rdp, sec_flags); @@ -988,7 +988,7 @@ BOOL rdp_send_message_channel_pdu(rdpRdp* rdp, wStream* s, UINT16 sec_flags) { size_t length = Stream_GetPosition(s); - Stream_SetPosition(s, 0); + Stream_ResetPosition(s); if (!rdp_write_header(rdp, s, length, rdp->mcs->messageChannelId, sec_flags)) goto fail; @@ -1190,10 +1190,10 @@ state_run_t rdp_recv_data_pdu(rdpRdp* rdp, wStream* s) return STATE_RUN_FAILED; } - Stream_SetPosition(cs, 0); + Stream_ResetPosition(cs); Stream_Write(cs, pDstData, DstSize); Stream_SealLength(cs); - Stream_SetPosition(cs, 0); + Stream_ResetPosition(cs); } else { diff --git a/libfreerdp/core/server.c b/libfreerdp/core/server.c index 96c94c1a7..bbc932022 100644 --- a/libfreerdp/core/server.c +++ b/libfreerdp/core/server.c @@ -221,7 +221,7 @@ static BOOL wts_read_drdynvc_data_first(rdpPeerChannel* channel, wStream* s, int if (length > channel->dvc_total_length) return FALSE; - Stream_SetPosition(channel->receiveData, 0); + Stream_ResetPosition(channel->receiveData); if (!Stream_EnsureRemainingCapacity(channel->receiveData, channel->dvc_total_length)) return FALSE; @@ -288,7 +288,7 @@ static BOOL wts_read_drdynvc_pdu(rdpPeerChannel* channel) if ((length < 1) || (length > UINT32_MAX)) return FALSE; - Stream_SetPosition(channel->receiveData, 0); + Stream_ResetPosition(channel->receiveData); const UINT8 value = Stream_Get_UINT8(channel->receiveData); length--; Cmd = (value & 0xf0) >> 4; @@ -457,7 +457,7 @@ static BOOL WTSProcessChannelData(rdpPeerChannel* channel, UINT16 channelId, con if (flags & CHANNEL_FLAG_FIRST) { - Stream_SetPosition(channel->receiveData, 0); + Stream_ResetPosition(channel->receiveData); } if (!Stream_EnsureRemainingCapacity(channel->receiveData, size)) @@ -486,7 +486,7 @@ static BOOL WTSProcessChannelData(rdpPeerChannel* channel, UINT16 channelId, con (UINT32)pos); } - Stream_SetPosition(channel->receiveData, 0); + Stream_ResetPosition(channel->receiveData); } return ret; diff --git a/libfreerdp/core/streamdump.c b/libfreerdp/core/streamdump.c index e8f9d193c..cbd2b3afb 100644 --- a/libfreerdp/core/streamdump.c +++ b/libfreerdp/core/streamdump.c @@ -375,7 +375,7 @@ static int stream_dump_replay_transport_read(rdpTransport* transport, wStream* s ctx->dump->replayTime = ts; size = Stream_Length(s); - Stream_SetPosition(s, 0); + Stream_ResetPosition(s); WLog_Print(ctx->dump->log, WLOG_TRACE, "replay read %" PRIuz, size); if (slp > 0) diff --git a/libfreerdp/core/transport.c b/libfreerdp/core/transport.c index 8d0339423..e0801e15e 100644 --- a/libfreerdp/core/transport.c +++ b/libfreerdp/core/transport.c @@ -1185,7 +1185,7 @@ static int transport_default_read_pdu(rdpTransport* transport, wStream* s) } Stream_SealLength(s); - Stream_SetPosition(s, 0); + Stream_ResetPosition(s); const size_t len = Stream_Length(s); if (len > INT32_MAX) return -1; @@ -1224,7 +1224,7 @@ static int transport_default_write(rdpTransport* transport, wStream* s) { size_t length = Stream_GetPosition(s); size_t writtenlength = length; - Stream_SetPosition(s, 0); + Stream_ResetPosition(s); if (length > 0) { diff --git a/libfreerdp/emu/scard/smartcard_virtual_gids.c b/libfreerdp/emu/scard/smartcard_virtual_gids.c index 8a0e68d62..b9fec815c 100644 --- a/libfreerdp/emu/scard/smartcard_virtual_gids.c +++ b/libfreerdp/emu/scard/smartcard_virtual_gids.c @@ -339,11 +339,7 @@ static BOOL vgids_ef_write_do(vgidsEF* ef, UINT16 doID, const void* data, DWORD static BOOL vgids_ef_read_do(vgidsEF* ef, UINT16 doID, BYTE** data, DWORD* dataSize) { /* Read the given DO from the file: 2-Byte ID, 1-Byte Len, Data */ - if (!Stream_SetPosition(ef->data, 0)) - { - WLog_ERR(TAG, "Failed to seek to front of file"); - return FALSE; - } + Stream_ResetPosition(ef->data); /* Look for the requested DO */ while (Stream_GetRemainingLength(ef->data) > 3) @@ -844,7 +840,7 @@ static BOOL vgids_get_public_key(vgidsContext* context, UINT16 doTag) goto handle_error; /* set response data */ - Stream_SetPosition(response, 0); + Stream_ResetPosition(response); context->responseData = response; response = nullptr; @@ -1066,7 +1062,7 @@ static BOOL vgids_perform_digital_signature(vgidsContext* context) vgids_reset_context_response(context); /* for each digest info */ - Stream_SetPosition(context->commandData, 0); + Stream_ResetPosition(context->commandData); for (int i = 0; i < VGIDS_MAX_DIGEST_INFO; ++i) { /* have we found our digest? */ diff --git a/libfreerdp/utils/rdpdr_utils.c b/libfreerdp/utils/rdpdr_utils.c index 94737c818..2f74b4a08 100644 --- a/libfreerdp/utils/rdpdr_utils.c +++ b/libfreerdp/utils/rdpdr_utils.c @@ -261,9 +261,10 @@ BOOL rdpdr_write_iocompletion_header(wStream* out, UINT32 DeviceId, UINT32 Compl NTSTATUS ioStatus) { WINPR_ASSERT(out); - Stream_SetPosition(out, 0); + Stream_ResetPosition(out); if (!Stream_EnsureRemainingCapacity(out, 16)) return FALSE; + Stream_Write_UINT16(out, RDPDR_CTYP_CORE); /* Component (2 bytes) */ Stream_Write_UINT16(out, PAKID_CORE_DEVICE_IOCOMPLETION); /* PacketId (2 bytes) */ Stream_Write_UINT32(out, DeviceId); /* DeviceId (4 bytes) */ @@ -284,7 +285,7 @@ static void rdpdr_dump_packet(wLog* log, DWORD lvl, wStream* s, const char* cust UINT16 component = 0; UINT16 packetid = 0; - Stream_SetPosition(s, 0); + Stream_ResetPosition(s); if (pos >= 2) Stream_Read_UINT16(s, component); diff --git a/libfreerdp/utils/test/TestEncodedTypes.c b/libfreerdp/utils/test/TestEncodedTypes.c index 92530d4b0..401475713 100644 --- a/libfreerdp/utils/test/TestEncodedTypes.c +++ b/libfreerdp/utils/test/TestEncodedTypes.c @@ -46,12 +46,8 @@ static BOOL test_signed_integer_read_write_equal(INT32 value) (void)fprintf(stderr, "[%s(%" PRId32 ")] failed to write to stream\n", __func__, value); return FALSE; } - if (!Stream_SetPosition(s, 0)) - { - (void)fprintf(stderr, "[%s(%" PRId32 ")] failed to reset stream position\n", __func__, - value); - return FALSE; - } + Stream_ResetPosition(s); + if (!freerdp_read_four_byte_signed_integer(s, &rvalue)) { (void)fprintf(stderr, "[%s(%" PRId32 ")] failed to read from stream\n", __func__, value); @@ -131,11 +127,8 @@ static BOOL test_float_read_write_equal(double value) (void)fprintf(stderr, "[%s(%lf)] failed to write to stream\n", __func__, value); return FALSE; } - if (!Stream_SetPosition(s, 0)) - { - (void)fprintf(stderr, "[%s(%lf)] failed to reset stream position\n", __func__, value); - return FALSE; - } + Stream_ResetPosition(s); + if (!freerdp_read_four_byte_float_exp(s, &rvalue, &exp)) { (void)fprintf(stderr, "[%s(%lf)] failed to read from stream\n", __func__, value); diff --git a/server/Mac/mf_peer.c b/server/Mac/mf_peer.c index 4b08859af..73c546671 100644 --- a/server/Mac/mf_peer.c +++ b/server/Mac/mf_peer.c @@ -109,7 +109,7 @@ static void mf_peer_rfx_update(freerdp_peer* client) WINPR_ASSERT(s); Stream_Clear(s); - Stream_SetPosition(s, 0); + Stream_ResetPosition(s); UINT32 x = mfi->invalid.x / mfi->scale; UINT32 y = mfi->invalid.y / mfi->scale; rect.x = 0; diff --git a/server/Sample/sfreerdp.c b/server/Sample/sfreerdp.c index 5242d1670..daafec5c6 100644 --- a/server/Sample/sfreerdp.c +++ b/server/Sample/sfreerdp.c @@ -172,7 +172,7 @@ static wStream* test_peer_stream_init(testPeerContext* context) WINPR_ASSERT(context->s); Stream_Clear(context->s); - Stream_SetPosition(context->s, 0); + Stream_ResetPosition(context->s); return context->s; } @@ -652,7 +652,7 @@ static DWORD WINAPI tf_debug_channel_thread_func(LPVOID arg) goto fail; } - Stream_SetPosition(s, 0); + Stream_ResetPosition(s); if (WTSVirtualChannelRead(context->debug_channel, 0, Stream_BufferAs(s, char), (ULONG)Stream_Capacity(s), &BytesReturned) == FALSE) @@ -1108,7 +1108,7 @@ static int hook_peer_write_pdu(rdpTransport* transport, wStream* s) if (rc < 0) goto fail; } - Stream_SetPosition(ls, 0); + Stream_ResetPosition(ls); } fail: diff --git a/server/Windows/wf_update.c b/server/Windows/wf_update.c index 18265ca79..3bbdec108 100644 --- a/server/Windows/wf_update.c +++ b/server/Windows/wf_update.c @@ -113,7 +113,7 @@ void wf_update_encode(wfInfo* wfi) SURFACE_BITS_COMMAND* cmd; wf_info_find_invalid_region(wfi); cmd = &wfi->cmd; - Stream_SetPosition(wfi->s, 0); + Stream_ResetPosition(wfi->s); wf_info_getScreenData(wfi, &width, &height, &pDataBits, &stride); rect.x = 0; rect.y = 0; diff --git a/server/proxy/channels/pf_channel_drdynvc.c b/server/proxy/channels/pf_channel_drdynvc.c index 25ce2fed5..826aa863f 100644 --- a/server/proxy/channels/pf_channel_drdynvc.c +++ b/server/proxy/channels/pf_channel_drdynvc.c @@ -334,7 +334,7 @@ static PfChannelResult DynvcTrackerPeekHandleByMode(ChannelStateTracker* tracker trackerState->CurrentDataReceived = 0; if (dynChannel->packetReassembly && trackerState->currentPacket) - Stream_SetPosition(trackerState->currentPacket, 0); + Stream_ResetPosition(trackerState->currentPacket); } return result; @@ -551,7 +551,7 @@ static PfChannelResult DynvcTrackerHandleCmdDATA(ChannelStateTracker* tracker, if (dynChannel->packetReassembly) { if (trackerState->currentPacket) - Stream_SetPosition(trackerState->currentPacket, 0); + Stream_ResetPosition(trackerState->currentPacket); } } break; diff --git a/server/proxy/channels/pf_channel_rdpdr.c b/server/proxy/channels/pf_channel_rdpdr.c index 57326b1ba..6e8c95c1a 100644 --- a/server/proxy/channels/pf_channel_rdpdr.c +++ b/server/proxy/channels/pf_channel_rdpdr.c @@ -199,8 +199,8 @@ static wStream* rdpdr_get_send_buffer(pf_channel_common_context* rdpdr, UINT16 c { WINPR_ASSERT(rdpdr); WINPR_ASSERT(rdpdr->s); - if (!Stream_SetPosition(rdpdr->s, 0)) - return nullptr; + Stream_ResetPosition(rdpdr->s); + if (!Stream_EnsureCapacity(rdpdr->s, capacity + 4)) return nullptr; Stream_Write_UINT16(rdpdr->s, component); @@ -1068,7 +1068,7 @@ static BOOL pf_channel_rdpdr_rewrite_device_list_to(wStream* s, UINT32 fromVersi Stream_Copy(s, clone, cap); Stream_SealLength(clone); - Stream_SetPosition(clone, 0); + Stream_ResetPosition(clone); Stream_SetPosition(s, pos); } @@ -1148,7 +1148,7 @@ static BOOL pf_channel_rdpdr_rewrite_device_list(pf_channel_client_context* rdpd const size_t pos = Stream_GetPosition(s); UINT16 component = 0; UINT16 packetid = 0; - Stream_SetPosition(s, 0); + Stream_ResetPosition(s); if (!Stream_CheckAndLogRequiredLengthWLog(rdpdr->log, s, 4)) return FALSE; @@ -1381,7 +1381,7 @@ BOOL pf_channel_rdpdr_client_handle(pClientContext* pc, UINT16 channelId, const } s = rdpdr->common.buffer; if (flags & CHANNEL_FLAG_FIRST) - Stream_SetPosition(s, 0); + Stream_ResetPosition(s); if (!Stream_EnsureRemainingCapacity(s, xsize)) { CLIENT_RX_LOG(rdpdr->log, WLOG_ERROR, @@ -1394,7 +1394,7 @@ BOOL pf_channel_rdpdr_client_handle(pClientContext* pc, UINT16 channelId, const return TRUE; Stream_SealLength(s); - Stream_SetPosition(s, 0); + Stream_ResetPosition(s); if (Stream_Length(s) != totalSize) { CLIENT_RX_LOG(rdpdr->log, WLOG_WARN, @@ -1919,7 +1919,7 @@ BOOL pf_channel_rdpdr_server_handle(pServerContext* ps, UINT16 channelId, const s = rdpdr->common.buffer; if (flags & CHANNEL_FLAG_FIRST) - Stream_SetPosition(s, 0); + Stream_ResetPosition(s); if (!Stream_EnsureRemainingCapacity(s, xsize)) return FALSE; @@ -1929,7 +1929,7 @@ BOOL pf_channel_rdpdr_server_handle(pServerContext* ps, UINT16 channelId, const return TRUE; Stream_SealLength(s); - Stream_SetPosition(s, 0); + Stream_ResetPosition(s); if (Stream_Length(s) != totalSize) { diff --git a/server/proxy/channels/pf_channel_smartcard.c b/server/proxy/channels/pf_channel_smartcard.c index da1a9c3f2..1b9a60a62 100644 --- a/server/proxy/channels/pf_channel_smartcard.c +++ b/server/proxy/channels/pf_channel_smartcard.c @@ -84,7 +84,7 @@ static BOOL pf_channel_client_write_iostatus(wStream* out, const SMARTCARD_OPERA WINPR_ASSERT(out); pos = Stream_GetPosition(out); - Stream_SetPosition(out, 0); + Stream_ResetPosition(out); if (!Stream_CheckAndLogRequiredLength(TAG, out, 16)) return FALSE; diff --git a/server/proxy/modules/bitmap-filter/bitmap-filter.cpp b/server/proxy/modules/bitmap-filter/bitmap-filter.cpp index 720b0011a..80c634245 100644 --- a/server/proxy/modules/bitmap-filter/bitmap-filter.cpp +++ b/server/proxy/modules/bitmap-filter/bitmap-filter.cpp @@ -209,7 +209,7 @@ class DynChannelState [[nodiscard]] static BOOL drdynvc_try_read_header(wStream* s, uint32_t& channelId, size_t& length) { UINT8 value = 0; - Stream_SetPosition(s, 0); + Stream_ResetPosition(s); if (Stream_GetRemainingLength(s) < 1) return FALSE; Stream_Read_UINT8(s, value); diff --git a/server/proxy/pf_channel.c b/server/proxy/pf_channel.c index cefdc9bb2..73aca75c5 100644 --- a/server/proxy/pf_channel.c +++ b/server/proxy/pf_channel.c @@ -60,7 +60,7 @@ static BOOL channelTracker_resetCurrentPacket(ChannelStateTracker* tracker) tracker->currentPacket = Stream_New(nullptr, 10ULL * 1024ULL); if (!tracker->currentPacket) return FALSE; - Stream_SetPosition(tracker->currentPacket, 0); + Stream_ResetPosition(tracker->currentPacket); return TRUE; } diff --git a/server/proxy/pf_client.c b/server/proxy/pf_client.c index d0c157208..27ab3c350 100644 --- a/server/proxy/pf_client.c +++ b/server/proxy/pf_client.c @@ -923,7 +923,7 @@ static int pf_client_verify_X509_certificate(freerdp* instance, const BYTE* data if (!Stream_EnsureCapacity(pc->remote_pem, length)) return 0; - Stream_SetPosition(pc->remote_pem, 0); + Stream_ResetPosition(pc->remote_pem); free(pc->remote_hostname); pc->remote_hostname = nullptr; diff --git a/server/shadow/shadow_client.c b/server/shadow/shadow_client.c index 268e164f8..2a436c1bb 100644 --- a/server/shadow/shadow_client.c +++ b/server/shadow/shadow_client.c @@ -1601,7 +1601,7 @@ static BOOL shadow_client_send_surface_bits(rdpShadowClient* client, BYTE* pSrcD for (size_t i = 0; i < numMessages; i++) { - Stream_SetPosition(s, 0); + Stream_ResetPosition(s); const RFX_MESSAGE* msg = rfx_message_list_get(messages, i); if (!rfx_write_message(encoder->rfx, s, msg)) @@ -1642,7 +1642,7 @@ static BOOL shadow_client_send_surface_bits(rdpShadowClient* client, BYTE* pSrcD } s = encoder->bs; - Stream_SetPosition(s, 0); + Stream_ResetPosition(s); pSrcData = &pSrcData[(nYSrc * nSrcStep) + (nXSrc * 4)]; if (!nsc_compose_message(encoder->nsc, s, pSrcData, nWidth, nHeight, nSrcStep)) return FALSE; diff --git a/winpr/include/winpr/stream.h b/winpr/include/winpr/stream.h index 17294076f..839cef953 100644 --- a/winpr/include/winpr/stream.h +++ b/winpr/include/winpr/stream.h @@ -1319,6 +1319,20 @@ extern "C" return WINPR_STREAM_CAST(size_t, (_s->pointer - _s->buffer)); } + /** @brief helper to reset stream read/write position to beginning of stream. + * + * Same as \ref Stream_SetPosition(s, 0) but does not need bounds checks. + * + * @param _s A stream to reset the position on. Must not be \b nullptr + * + * @since version 3.24.0 + */ + static inline void Stream_ResetPosition(wStream* _s) + { + WINPR_ASSERT(_s); + _s->pointer = _s->buffer; + } + WINPR_API BOOL Stream_SetPosition(wStream* _s, size_t _p); WINPR_API void Stream_SealLength(wStream* _s); diff --git a/winpr/libwinpr/utils/collections/StreamPool.c b/winpr/libwinpr/utils/collections/StreamPool.c index 36b1c6340..a6b24cd8f 100644 --- a/winpr/libwinpr/utils/collections/StreamPool.c +++ b/winpr/libwinpr/utils/collections/StreamPool.c @@ -246,7 +246,7 @@ wStream* StreamPool_Take(wStreamPool* pool, size_t size) } else if (s) { - Stream_SetPosition(s, 0); + Stream_ResetPosition(s); Stream_SetLength(s, Stream_Capacity(s)); StreamPool_ShiftAvailable(pool, foundIndex); } diff --git a/winpr/libwinpr/utils/test/TestStream.c b/winpr/libwinpr/utils/test/TestStream.c index b8f7619b1..6474b7103 100644 --- a/winpr/libwinpr/utils/test/TestStream.c +++ b/winpr/libwinpr/utils/test/TestStream.c @@ -97,13 +97,13 @@ static BOOL TestStream_Static(void) /* Test creation of a static stream */ Stream_StaticInit(s, buffer, sizeof(buffer)); Stream_Write_UINT16(s, 0xcab1); - Stream_SetPosition(s, 0); + Stream_ResetPosition(s); Stream_Read_UINT16(s, v); if (v != 0xcab1) return FALSE; - Stream_SetPosition(s, 0); + Stream_ResetPosition(s); Stream_Write_UINT16(s, 1); if (!Stream_EnsureRemainingCapacity(s, 10)) /* we can ask for 10 bytes */ @@ -114,7 +114,7 @@ static BOOL TestStream_Static(void) return FALSE; Stream_Write_UINT16(s, 2); - Stream_SetPosition(s, 0); + Stream_ResetPosition(s); Stream_Read_UINT16(s, v); if (v != 1) @@ -264,7 +264,7 @@ fail: _t _a = 0; \ _t _b = 0; \ BYTE* _p = Stream_Buffer(_s); \ - Stream_SetPosition(_s, 0); \ + Stream_ResetPosition(_s); \ Stream_Peek_##_t(_s, _a); \ Stream_Read_##_t(_s, _b); \ if (_a != _b) \ @@ -290,7 +290,7 @@ fail: } \ } \ /* printf("a: 0x%016llX\n", a); */ \ - Stream_SetPosition(_s, 0); \ + Stream_ResetPosition(_s); \ Stream_Peek_##_t##_BE(_s, _a); \ Stream_Read_##_t##_BE(_s, _b); \ if (_a != _b) \ @@ -505,7 +505,7 @@ static BOOL TestStream_Write(void) if (s->pointer != s->buffer + sizeof(data)) goto out; - Stream_SetPosition(s, 0); + Stream_ResetPosition(s); if (s->pointer != s->buffer) goto out; @@ -515,7 +515,7 @@ static BOOL TestStream_Write(void) if (s->pointer != s->buffer + 1) goto out; - Stream_SetPosition(s, 0); + Stream_ResetPosition(s); if (s->pointer != s->buffer) goto out; @@ -530,7 +530,7 @@ static BOOL TestStream_Write(void) if (s->pointer != s->buffer + 2) goto out; - Stream_SetPosition(s, 0); + Stream_ResetPosition(s); if (s->pointer != s->buffer) goto out; @@ -545,7 +545,7 @@ static BOOL TestStream_Write(void) if (s->pointer != s->buffer + 4) goto out; - Stream_SetPosition(s, 0); + Stream_ResetPosition(s); if (s->pointer != s->buffer) goto out; @@ -560,7 +560,7 @@ static BOOL TestStream_Write(void) if (s->pointer != s->buffer + 8) goto out; - Stream_SetPosition(s, 0); + Stream_ResetPosition(s); if (s->pointer != s->buffer) goto out; @@ -678,7 +678,7 @@ static BOOL TestStream_Zero(void) if (memcmp(Stream_Buffer(s), data, sizeof(data)) != 0) goto out; - Stream_SetPosition(s, 0); + Stream_ResetPosition(s); if (s->pointer != s->buffer) goto out; @@ -691,7 +691,7 @@ static BOOL TestStream_Zero(void) if (memcmp(Stream_ConstPointer(s), data + 5, sizeof(data) - 5) != 0) goto out; - Stream_SetPosition(s, 0); + Stream_ResetPosition(s); if (s->pointer != s->buffer) goto out; @@ -726,7 +726,7 @@ static BOOL TestStream_Fill(void) if (memcmp(Stream_Buffer(s), data, sizeof(data)) != 0) goto out; - Stream_SetPosition(s, 0); + Stream_ResetPosition(s); if (s->pointer != s->buffer) goto out; @@ -739,7 +739,7 @@ static BOOL TestStream_Fill(void) if (memcmp(Stream_ConstPointer(s), data + sizeof(fill), sizeof(data) - sizeof(fill)) != 0) goto out; - Stream_SetPosition(s, 0); + Stream_ResetPosition(s); if (s->pointer != s->buffer) goto out; @@ -774,7 +774,7 @@ static BOOL TestStream_Copy(void) if (s->pointer != s->buffer + sizeof(data)) goto out; - Stream_SetPosition(s, 0); + Stream_ResetPosition(s); if (s->pointer != s->buffer) goto out;