Merge pull request #11322 from akallabeth/urbdrc-leak

Urbdrc leak fix
This commit is contained in:
akallabeth
2025-03-11 16:02:58 +01:00
committed by GitHub
36 changed files with 337 additions and 237 deletions

View File

@@ -945,7 +945,6 @@ static UINT drdynvc_write_data(drdynvcPlugin* drdynvc, UINT32 ChannelId, const B
size_t pos = 0;
UINT8 cbChId = 0;
UINT8 cbLen = 0;
unsigned long chunkLength = 0;
UINT status = CHANNEL_RC_BAD_INIT_HANDLE;
DVCMAN* dvcman = NULL;
@@ -993,10 +992,16 @@ static UINT drdynvc_write_data(drdynvcPlugin* drdynvc, UINT32 ChannelId, const B
const INT32 pdu = (DATA_FIRST_PDU << 4) | cbChId | (cbLen << 2);
Stream_Write_UINT8(data_out, WINPR_ASSERTING_INT_CAST(UINT8, pdu));
Stream_SetPosition(data_out, pos);
chunkLength = CHANNEL_CHUNK_LENGTH - pos;
Stream_Write(data_out, data, chunkLength);
data += chunkLength;
dataSize -= chunkLength;
{
WINPR_ASSERT(pos <= CHANNEL_CHUNK_LENGTH);
const uint32_t chunkLength =
CHANNEL_CHUNK_LENGTH - WINPR_ASSERTING_INT_CAST(uint32_t, pos);
Stream_Write(data_out, data, chunkLength);
data += chunkLength;
dataSize -= chunkLength;
}
status = drdynvc_send(drdynvc, data_out);
while (status == CHANNEL_RC_OK && dataSize > 0)
@@ -1015,10 +1020,12 @@ static UINT drdynvc_write_data(drdynvcPlugin* drdynvc, UINT32 ChannelId, const B
Stream_SetPosition(data_out, 0);
Stream_Write_UINT8(data_out, (DATA_PDU << 4) | cbChId);
Stream_SetPosition(data_out, pos);
chunkLength = dataSize;
uint32_t chunkLength = dataSize;
WINPR_ASSERT(pos <= CHANNEL_CHUNK_LENGTH);
if (chunkLength > CHANNEL_CHUNK_LENGTH - pos)
chunkLength = CHANNEL_CHUNK_LENGTH - pos;
chunkLength = CHANNEL_CHUNK_LENGTH - WINPR_ASSERTING_INT_CAST(uint32_t, pos);
Stream_Write(data_out, data, chunkLength);
data += chunkLength;

View File

@@ -387,7 +387,9 @@ static UINT rdpei_send_pen_frame(RdpeiClientContext* context, RDPINPUT_PEN_FRAME
frame->frameOffset = rdpei->currentPenFrameTime - rdpei->previousPenFrameTime;
}
if ((error = rdpei_send_pen_event_pdu(callback, frame->frameOffset, frame, 1)))
const size_t off = WINPR_ASSERTING_INT_CAST(size_t, frame->frameOffset);
error = rdpei_send_pen_event_pdu(callback, off, frame, 1);
if (error)
return error;
rdpei->previousPenFrameTime = rdpei->currentPenFrameTime;

View File

@@ -654,6 +654,7 @@ static UINT urb_select_interface(IUDEVICE* pdev, GENERIC_CHANNEL_CALLBACK* callb
"[MS-RDPEUSB] 2.2.9.3 TS_URB_SELECT_INTERFACE::OutputBufferSize must be 0, got "
"%" PRIu32,
OutputBufferSize);
msusb_msinterface_free(MsInterface);
return ERROR_INVALID_DATA;
}

View File

@@ -159,8 +159,8 @@ bool SDLConnectionDialog::clearWindow(SDL_Renderer* renderer)
{
assert(renderer);
const int drc = SDL_SetRenderDrawColor(renderer, backgroundcolor.r, backgroundcolor.g,
backgroundcolor.b, backgroundcolor.a);
const auto drc = SDL_SetRenderDrawColor(renderer, backgroundcolor.r, backgroundcolor.g,
backgroundcolor.b, backgroundcolor.a);
if (widget_log_error(drc, "SDL_SetRenderDrawColor"))
return false;

View File

@@ -50,12 +50,12 @@ SdlWidget::SdlWidget([[maybe_unused]] SDL_Renderer* renderer, const SDL_FRect& r
auto ops = SDL3ResourceManager::get(SDLResourceManager::typeFonts(),
"OpenSans-VariableFont_wdth,wght.ttf");
if (!ops)
widget_log_error(-1, "SDLResourceManager::get");
widget_log_error(false, "SDLResourceManager::get");
else
{
_font = TTF_OpenFontIO(ops, true, 64);
if (!_font)
widget_log_error(-1, "TTF_OpenFontRW");
widget_log_error(false, "TTF_OpenFontRW");
}
}
@@ -66,7 +66,7 @@ SdlWidget::SdlWidget(SDL_Renderer* renderer, const SDL_FRect& rect, SDL_IOStream
{
_image = IMG_LoadTexture_IO(renderer, ops, 1);
if (!_image)
widget_log_error(-1, "IMG_LoadTexture_IO");
widget_log_error(false, "IMG_LoadTexture_IO");
}
}
#endif
@@ -85,7 +85,7 @@ SDL_Texture* SdlWidget::render_text(SDL_Renderer* renderer, const std::string& t
auto surface = TTF_RenderText_Blended(_font, text.c_str(), 0, fgcolor);
if (!surface)
{
widget_log_error(-1, "TTF_RenderText_Blended");
widget_log_error(false, "TTF_RenderText_Blended");
return nullptr;
}
@@ -93,7 +93,7 @@ SDL_Texture* SdlWidget::render_text(SDL_Renderer* renderer, const std::string& t
SDL_DestroySurface(surface);
if (!texture)
{
widget_log_error(-1, "SDL_CreateTextureFromSurface");
widget_log_error(false, "SDL_CreateTextureFromSurface");
return nullptr;
}
@@ -101,7 +101,7 @@ SDL_Texture* SdlWidget::render_text(SDL_Renderer* renderer, const std::string& t
TTF_CreateRendererTextEngine(renderer), TTF_DestroySurfaceTextEngine);
if (!engine)
{
widget_log_error(-1, "TTF_CreateRendererTextEngine");
widget_log_error(false, "TTF_CreateRendererTextEngine");
return nullptr;
}
@@ -110,14 +110,14 @@ SDL_Texture* SdlWidget::render_text(SDL_Renderer* renderer, const std::string& t
if (!txt)
{
widget_log_error(-1, "TTF_CreateText");
widget_log_error(false, "TTF_CreateText");
return nullptr;
}
int w = 0;
int h = 0;
if (!TTF_GetTextSize(txt.get(), &w, &h))
{
widget_log_error(-1, "TTF_GetTextSize");
widget_log_error(false, "TTF_GetTextSize");
return nullptr;
}
@@ -159,7 +159,7 @@ SDL_Texture* SdlWidget::render_text_wrapped(SDL_Renderer* renderer, const std::s
static_cast<int>(_text_width));
if (!surface)
{
widget_log_error(-1, "TTF_RenderText_Blended");
widget_log_error(false, "TTF_RenderText_Blended");
return nullptr;
}
@@ -170,7 +170,7 @@ SDL_Texture* SdlWidget::render_text_wrapped(SDL_Renderer* renderer, const std::s
SDL_DestroySurface(surface);
if (!texture)
{
widget_log_error(-1, "SDL_CreateTextureFromSurface");
widget_log_error(false, "SDL_CreateTextureFromSurface");
return nullptr;
}
@@ -213,11 +213,11 @@ bool SdlWidget::error_ex(bool success, const char* what, const char* file, size_
static bool draw_rect(SDL_Renderer* renderer, const SDL_FRect* rect, SDL_Color color)
{
const int drc = SDL_SetRenderDrawColor(renderer, color.r, color.g, color.b, color.a);
const auto drc = SDL_SetRenderDrawColor(renderer, color.r, color.g, color.b, color.a);
if (widget_log_error(drc, "SDL_SetRenderDrawColor"))
return false;
const int rc = SDL_RenderFillRect(renderer, rect);
const auto rc = SDL_RenderFillRect(renderer, rect);
return !widget_log_error(rc, "SDL_RenderFillRect");
}
@@ -287,7 +287,7 @@ bool SdlWidget::update_text(SDL_Renderer* renderer, const std::string& text, SDL
auto w = SDL_GetNumberProperty(propId, SDL_PROP_TEXTURE_WIDTH_NUMBER, -1);
auto h = SDL_GetNumberProperty(propId, SDL_PROP_TEXTURE_HEIGHT_NUMBER, -1);
if (w < 0 || h < 0)
widget_log_error(-1, "SDL_GetTextureProperties");
widget_log_error(false, "SDL_GetTextureProperties");
src.w = static_cast<float>(w);
src.h = static_cast<float>(h);
}
@@ -298,23 +298,22 @@ bool SdlWidget::update_text(SDL_Renderer* renderer, const std::string& text, SDL
if (!texture)
return false;
const int rc = SDL_RenderTexture(renderer, texture, &src, &dst);
const auto rc = SDL_RenderTexture(renderer, texture, &src, &dst);
if (!_image)
SDL_DestroyTexture(texture);
if (rc < 0)
return !widget_log_error(rc, "SDL_RenderCopy");
return true;
return !widget_log_error(rc, "SDL_RenderCopy");
}
bool clear_window(SDL_Renderer* renderer)
{
assert(renderer);
const int drc = SDL_SetRenderDrawColor(renderer, backgroundcolor.r, backgroundcolor.g,
backgroundcolor.b, backgroundcolor.a);
const auto drc = SDL_SetRenderDrawColor(renderer, backgroundcolor.r, backgroundcolor.g,
backgroundcolor.b, backgroundcolor.a);
if (widget_log_error(drc, "SDL_SetRenderDrawColor"))
return false;
const int rcls = SDL_RenderClear(renderer);
const auto rcls = SDL_RenderClear(renderer);
return !widget_log_error(rcls, "SDL_RenderClear");
}

View File

@@ -442,7 +442,8 @@ BOOL xf_generic_MotionNotify(xfContext* xfc, int x, int y, int state, Window win
if (xfc->fullscreen && !app)
{
XSetInputFocus(xfc->display, xfc->window->handle, RevertToPointerRoot, CurrentTime);
if (xfc->window)
XSetInputFocus(xfc->display, xfc->window->handle, RevertToPointerRoot, CurrentTime);
}
return TRUE;

View File

@@ -797,21 +797,21 @@ static INLINE BOOL freerdp_image_copy_bgr24_bgrx32(BYTE* WINPR_RESTRICT pDstData
UINT32 nHeight,
const BYTE* WINPR_RESTRICT pSrcData,
UINT32 nSrcStep, UINT32 nXSrc, UINT32 nYSrc,
SSIZE_T srcVMultiplier, SSIZE_T srcVOffset,
SSIZE_T dstVMultiplier, SSIZE_T dstVOffset)
int64_t srcVMultiplier, int64_t srcVOffset,
int64_t dstVMultiplier, int64_t dstVOffset)
{
const SSIZE_T srcByte = 3;
const SSIZE_T dstByte = 4;
const int64_t srcByte = 3;
const int64_t dstByte = 4;
for (SSIZE_T y = 0; y < nHeight; y++)
for (int64_t y = 0; y < nHeight; y++)
{
const BYTE* WINPR_RESTRICT srcLine =
&pSrcData[srcVMultiplier * (y + nYSrc) * nSrcStep + srcVOffset];
BYTE* WINPR_RESTRICT dstLine =
&pDstData[dstVMultiplier * (y + nYDst) * nDstStep + dstVOffset];
for (SSIZE_T x = 0; x < nWidth; x++)
for (int64_t x = 0; x < nWidth; x++)
{
dstLine[(x + nXDst) * dstByte + 0] = srcLine[(x + nXSrc) * srcByte + 0];
dstLine[(x + nXDst) * dstByte + 1] = srcLine[(x + nXSrc) * srcByte + 1];
@@ -827,21 +827,21 @@ static INLINE BOOL freerdp_image_copy_bgrx32_bgrx32(BYTE* WINPR_RESTRICT pDstDat
UINT32 nHeight,
const BYTE* WINPR_RESTRICT pSrcData,
UINT32 nSrcStep, UINT32 nXSrc, UINT32 nYSrc,
SSIZE_T srcVMultiplier, SSIZE_T srcVOffset,
SSIZE_T dstVMultiplier, SSIZE_T dstVOffset)
int64_t srcVMultiplier, int64_t srcVOffset,
int64_t dstVMultiplier, int64_t dstVOffset)
{
const SSIZE_T srcByte = 4;
const SSIZE_T dstByte = 4;
const int64_t srcByte = 4;
const int64_t dstByte = 4;
for (SSIZE_T y = 0; y < nHeight; y++)
for (int64_t y = 0; y < nHeight; y++)
{
const BYTE* WINPR_RESTRICT srcLine =
&pSrcData[srcVMultiplier * (y + nYSrc) * nSrcStep + srcVOffset];
BYTE* WINPR_RESTRICT dstLine =
&pDstData[dstVMultiplier * (y + nYDst) * nDstStep + dstVOffset];
for (SSIZE_T x = 0; x < nWidth; x++)
for (int64_t x = 0; x < nWidth; x++)
{
dstLine[(x + nXDst) * dstByte + 0] = srcLine[(x + nXSrc) * srcByte + 0];
dstLine[(x + nXDst) * dstByte + 1] = srcLine[(x + nXSrc) * srcByte + 1];
@@ -856,13 +856,13 @@ static INLINE BOOL freerdp_image_copy_generic(
BYTE* WINPR_RESTRICT pDstData, UINT32 DstFormat, UINT32 nDstStep, UINT32 nXDst, UINT32 nYDst,
UINT32 nWidth, UINT32 nHeight, const BYTE* WINPR_RESTRICT pSrcData, UINT32 SrcFormat,
UINT32 nSrcStep, UINT32 nXSrc, UINT32 nYSrc, const gdiPalette* WINPR_RESTRICT palette,
SSIZE_T srcVMultiplier, SSIZE_T srcVOffset, SSIZE_T dstVMultiplier, SSIZE_T dstVOffset)
int64_t srcVMultiplier, int64_t srcVOffset, int64_t dstVMultiplier, int64_t dstVOffset)
{
const SSIZE_T srcByte = 4;
const SSIZE_T dstByte = 4;
const int64_t srcByte = 4;
const int64_t dstByte = 4;
for (SSIZE_T y = 0; y < nHeight; y++)
for (int64_t y = 0; y < nHeight; y++)
{
const BYTE* WINPR_RESTRICT srcLine =
&pSrcData[srcVMultiplier * (y + nYSrc) * nSrcStep + srcVOffset];
@@ -873,7 +873,7 @@ static INLINE BOOL freerdp_image_copy_generic(
UINT32 oldColor = color;
UINT32 dstColor = FreeRDPConvertColor(color, SrcFormat, DstFormat, palette);
FreeRDPWriteColorIgnoreAlpha_int(&dstLine[nXDst * dstByte], DstFormat, dstColor);
for (SSIZE_T x = 1; x < nWidth; x++)
for (int64_t x = 1; x < nWidth; x++)
{
color = FreeRDPReadColor_int(&srcLine[(x + nXSrc) * srcByte], SrcFormat);
if (color == oldColor)
@@ -898,7 +898,7 @@ static INLINE BOOL freerdp_image_copy_no_overlap_dst_alpha(
BYTE* WINPR_RESTRICT pDstData, DWORD DstFormat, UINT32 nDstStep, UINT32 nXDst, UINT32 nYDst,
UINT32 nWidth, UINT32 nHeight, const BYTE* WINPR_RESTRICT pSrcData, DWORD SrcFormat,
UINT32 nSrcStep, UINT32 nXSrc, UINT32 nYSrc, const gdiPalette* WINPR_RESTRICT palette,
SSIZE_T srcVMultiplier, SSIZE_T srcVOffset, SSIZE_T dstVMultiplier, SSIZE_T dstVOffset)
int64_t srcVMultiplier, int64_t srcVOffset, int64_t dstVMultiplier, int64_t dstVOffset)
{
WINPR_ASSERT(pDstData);
WINPR_ASSERT(pSrcData);
@@ -950,10 +950,10 @@ BOOL freerdp_image_copy_overlap(BYTE* pDstData, DWORD DstFormat, UINT32 nDstStep
const UINT32 xSrcOffset = nXSrc * srcByte;
const UINT32 xDstOffset = nXDst * dstByte;
const BOOL vSrcVFlip = (flags & FREERDP_FLIP_VERTICAL) ? TRUE : FALSE;
SSIZE_T srcVOffset = 0;
SSIZE_T srcVMultiplier = 1;
SSIZE_T dstVOffset = 0;
SSIZE_T dstVMultiplier = 1;
int64_t srcVOffset = 0;
int64_t srcVMultiplier = 1;
int64_t dstVOffset = 0;
int64_t dstVMultiplier = 1;
WINPR_ASSERT(overlapping(pDstData, nYDst, nDstStep, pSrcData, nYSrc, nSrcStep, nHeight));
@@ -990,7 +990,7 @@ BOOL freerdp_image_copy_overlap(BYTE* pDstData, DWORD DstFormat, UINT32 nDstStep
/* Copy down */
if (nYDst < nYSrc)
{
for (SSIZE_T y = 0; y < nHeight; y++)
for (int64_t y = 0; y < nHeight; y++)
{
const BYTE* srcLine =
&pSrcData[(y + nYSrc) * nSrcStep * srcVMultiplier + srcVOffset];
@@ -1001,7 +1001,7 @@ BOOL freerdp_image_copy_overlap(BYTE* pDstData, DWORD DstFormat, UINT32 nDstStep
/* Copy up */
else if (nYDst > nYSrc)
{
for (SSIZE_T y = nHeight - 1; y >= 0; y--)
for (int64_t y = nHeight - 1; y >= 0; y--)
{
const BYTE* srcLine =
&pSrcData[srcVMultiplier * (y + nYSrc) * nSrcStep + srcVOffset];
@@ -1012,7 +1012,7 @@ BOOL freerdp_image_copy_overlap(BYTE* pDstData, DWORD DstFormat, UINT32 nDstStep
/* Copy left */
else if (nXSrc > nXDst)
{
for (SSIZE_T y = 0; y < nHeight; y++)
for (int64_t y = 0; y < nHeight; y++)
{
const BYTE* srcLine =
&pSrcData[srcVMultiplier * (y + nYSrc) * nSrcStep + srcVOffset];
@@ -1023,7 +1023,7 @@ BOOL freerdp_image_copy_overlap(BYTE* pDstData, DWORD DstFormat, UINT32 nDstStep
/* Copy right */
else if (nXSrc < nXDst)
{
for (SSIZE_T y = nHeight - 1; y >= 0; y--)
for (int64_t y = nHeight - 1; y >= 0; y--)
{
const BYTE* srcLine =
&pSrcData[srcVMultiplier * (y + nYSrc) * nSrcStep + srcVOffset];
@@ -1038,7 +1038,7 @@ BOOL freerdp_image_copy_overlap(BYTE* pDstData, DWORD DstFormat, UINT32 nDstStep
}
else
{
for (SSIZE_T y = 0; y < nHeight; y++)
for (int64_t y = 0; y < nHeight; y++)
{
const BYTE* srcLine = &pSrcData[srcVMultiplier * (y + nYSrc) * nSrcStep + srcVOffset];
BYTE* dstLine = &pDstData[dstVMultiplier * (y + nYDst) * nDstStep + dstVOffset];
@@ -1047,7 +1047,7 @@ BOOL freerdp_image_copy_overlap(BYTE* pDstData, DWORD DstFormat, UINT32 nDstStep
UINT32 oldColor = color;
UINT32 dstColor = FreeRDPConvertColor(color, SrcFormat, DstFormat, palette);
FreeRDPWriteColor_int(&dstLine[1ULL * nXDst * dstByte], DstFormat, dstColor);
for (SSIZE_T x = 1; x < nWidth; x++)
for (int64_t x = 1; x < nWidth; x++)
{
color = FreeRDPReadColor_int(&srcLine[(x + nXSrc) * srcByte], SrcFormat);
if (color == oldColor)

View File

@@ -518,27 +518,32 @@ int progressive_delete_surface_context(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progr
* LL3 4015 9x9 81
*/
static int16_t clampi16(int val)
{
if (val < INT16_MIN)
return INT16_MIN;
if (val > INT16_MAX)
return INT16_MAX;
return (int16_t)val;
}
static INLINE void progressive_rfx_idwt_x(const INT16* WINPR_RESTRICT pLowBand, size_t nLowStep,
const INT16* WINPR_RESTRICT pHighBand, size_t nHighStep,
INT16* WINPR_RESTRICT pDstBand, size_t nDstStep,
size_t nLowCount, size_t nHighCount, size_t nDstCount)
{
INT16 L0 = 0;
INT16 H0 = 0;
INT16 H1 = 0;
INT16 X0 = 0;
INT16 X1 = 0;
INT16 X2 = 0;
for (size_t i = 0; i < nDstCount; i++)
{
const INT16* pL = pLowBand;
const INT16* pH = pHighBand;
INT16* pX = pDstBand;
H0 = *pH++;
L0 = *pL++;
X0 = WINPR_ASSERTING_INT_CAST(int16_t, L0 - H0);
X2 = WINPR_ASSERTING_INT_CAST(int16_t, L0 - H0);
INT16 H0 = *pH++;
INT16 L0 = *pL++;
INT16 X0 = clampi16((int32_t)L0 - H0);
INT16 X2 = clampi16((int32_t)L0 - H0);
for (size_t j = 0; j < (nHighCount - 1); j++)
{
@@ -546,8 +551,8 @@ static INLINE void progressive_rfx_idwt_x(const INT16* WINPR_RESTRICT pLowBand,
pH++;
L0 = *pL;
pL++;
X2 = WINPR_ASSERTING_INT_CAST(int16_t, L0 - ((H0 + H1) / 2));
X1 = WINPR_ASSERTING_INT_CAST(int16_t, ((X0 + X2) / 2) + (2 * H0));
X2 = clampi16((int32_t)L0 - ((H0 + H1) / 2));
X1 = clampi16((int32_t)((X0 + X2) / 2) + (2 * H0));
pX[0] = X0;
pX[1] = X1;
pX += 2;
@@ -560,15 +565,15 @@ static INLINE void progressive_rfx_idwt_x(const INT16* WINPR_RESTRICT pLowBand,
if (nLowCount <= nHighCount)
{
pX[0] = X2;
pX[1] = WINPR_ASSERTING_INT_CAST(int16_t, X2 + (2 * H0));
pX[1] = clampi16((int32_t)X2 + (2 * H0));
}
else
{
L0 = *pL;
pL++;
X0 = WINPR_ASSERTING_INT_CAST(int16_t, L0 - H0);
X0 = clampi16((int32_t)L0 - H0);
pX[0] = X2;
pX[1] = WINPR_ASSERTING_INT_CAST(int16_t, ((X0 + X2) / 2) + (2 * H0));
pX[1] = clampi16((int32_t)((X0 + X2) / 2) + (2 * H0));
pX[2] = X0;
}
}
@@ -576,13 +581,13 @@ static INLINE void progressive_rfx_idwt_x(const INT16* WINPR_RESTRICT pLowBand,
{
L0 = *pL;
pL++;
X0 = WINPR_ASSERTING_INT_CAST(int16_t, L0 - (H0 / 2));
X0 = clampi16((int32_t)L0 - (H0 / 2));
pX[0] = X2;
pX[1] = WINPR_ASSERTING_INT_CAST(int16_t, ((X0 + X2) / 2) + (2 * H0));
pX[1] = clampi16((int32_t)((X0 + X2) / 2) + (2 * H0));
pX[2] = X0;
L0 = *pL;
pL++;
pX[3] = WINPR_ASSERTING_INT_CAST(int16_t, (X0 + L0) / 2);
pX[3] = clampi16((int32_t)(X0 + L0) / 2);
}
pLowBand += nLowStep;
@@ -596,24 +601,19 @@ static INLINE void progressive_rfx_idwt_y(const INT16* WINPR_RESTRICT pLowBand,
INT16* WINPR_RESTRICT pDstBand, size_t nDstStep,
size_t nLowCount, size_t nHighCount, size_t nDstCount)
{
INT16 L0 = 0;
INT16 H0 = 0;
INT16 H1 = 0;
INT16 X0 = 0;
INT16 X1 = 0;
INT16 X2 = 0;
for (size_t i = 0; i < nDstCount; i++)
{
INT16 H1 = 0;
INT16 X1 = 0;
const INT16* pL = pLowBand;
const INT16* pH = pHighBand;
INT16* pX = pDstBand;
H0 = *pH;
INT16 H0 = *pH;
pH += nHighStep;
L0 = *pL;
INT16 L0 = *pL;
pL += nLowStep;
X0 = WINPR_ASSERTING_INT_CAST(int16_t, L0 - H0);
X2 = WINPR_ASSERTING_INT_CAST(int16_t, L0 - H0);
int16_t X0 = clampi16((int32_t)L0 - H0);
int16_t X2 = clampi16((int32_t)L0 - H0);
for (size_t j = 0; j < (nHighCount - 1); j++)
{
@@ -621,8 +621,8 @@ static INLINE void progressive_rfx_idwt_y(const INT16* WINPR_RESTRICT pLowBand,
pH += nHighStep;
L0 = *pL;
pL += nLowStep;
X2 = WINPR_ASSERTING_INT_CAST(int16_t, L0 - ((H0 + H1) / 2));
X1 = WINPR_ASSERTING_INT_CAST(int16_t, ((X0 + X2) / 2) + (2 * H0));
X2 = clampi16((int32_t)L0 - ((H0 + H1) / 2));
X1 = clampi16((int32_t)((X0 + X2) / 2) + (2 * H0));
*pX = X0;
pX += nDstStep;
*pX = X1;
@@ -637,15 +637,15 @@ static INLINE void progressive_rfx_idwt_y(const INT16* WINPR_RESTRICT pLowBand,
{
*pX = X2;
pX += nDstStep;
*pX = WINPR_ASSERTING_INT_CAST(int16_t, X2 + (2 * H0));
*pX = clampi16((int32_t)X2 + (2 * H0));
}
else
{
L0 = *pL;
X0 = WINPR_ASSERTING_INT_CAST(int16_t, L0 - H0);
X0 = clampi16((int32_t)L0 - H0);
*pX = X2;
pX += nDstStep;
*pX = WINPR_ASSERTING_INT_CAST(int16_t, ((X0 + X2) / 2) + (2 * H0));
*pX = clampi16((int32_t)((X0 + X2) / 2) + (2 * H0));
pX += nDstStep;
*pX = X0;
}
@@ -654,15 +654,15 @@ static INLINE void progressive_rfx_idwt_y(const INT16* WINPR_RESTRICT pLowBand,
{
L0 = *pL;
pL += nLowStep;
X0 = WINPR_ASSERTING_INT_CAST(int16_t, L0 - (H0 / 2));
X0 = clampi16((int32_t)L0 - (H0 / 2));
*pX = X2;
pX += nDstStep;
*pX = WINPR_ASSERTING_INT_CAST(int16_t, ((X0 + X2) / 2) + (2 * H0));
*pX = clampi16((int32_t)((X0 + X2) / 2) + (2 * H0));
pX += nDstStep;
*pX = X0;
pX += nDstStep;
L0 = *pL;
*pX = WINPR_ASSERTING_INT_CAST(int16_t, (X0 + L0) / 2);
*pX = clampi16((int32_t)(X0 + L0) / 2);
}
pLowBand++;
@@ -746,8 +746,8 @@ static INLINE int progressive_rfx_dwt_2d_decode(PROGRESSIVE_CONTEXT* WINPR_RESTR
if (!progressive || !buffer || !current)
return -1;
const size_t belements = 4096;
const size_t bsize = belements * sizeof(INT16);
const uint32_t belements = 4096;
const uint32_t bsize = belements * sizeof(INT16);
if (reverse)
memcpy(buffer, current, bsize);
else if (!coeffDiff)

View File

@@ -1871,7 +1871,8 @@ skip_encoding_loop:
}
const RFX_TILE* tile = message->tiles[i];
message->tilesDataSize += rfx_tile_length(tile);
const size_t tlen = rfx_tile_length(tile);
message->tilesDataSize += WINPR_ASSERTING_INT_CAST(uint32_t, tlen);
}
region16_uninit(&tilesRegion);
@@ -1972,7 +1973,7 @@ static INLINE RFX_MESSAGE* rfx_split_message(RFX_CONTEXT* WINPR_RESTRICT context
goto free_messages;
}
msg->tilesDataSize += tileDataSize;
msg->tilesDataSize += WINPR_ASSERTING_INT_CAST(uint32_t, tileDataSize);
WINPR_ASSERT(msg->numTiles < msg->allocatedTiles);
msg->tiles[msg->numTiles++] = message->tiles[i];

View File

@@ -226,7 +226,8 @@ int rfx_rlgr_decode(RLGR_MODE mode, const BYTE* WINPR_RESTRICT pSrcData, UINT32
if (cnt > nbits)
cnt = nbits;
vk += cnt;
WINPR_ASSERT(cnt + vk <= UINT32_MAX);
vk += WINPR_ASSERTING_INT_CAST(uint32_t, cnt);
}
BitStream_Shift(bs, (vk % 32));
@@ -290,7 +291,8 @@ int rfx_rlgr_decode(RLGR_MODE mode, const BYTE* WINPR_RESTRICT pSrcData, UINT32
if (cnt > nbits)
cnt = nbits;
vk += cnt;
WINPR_ASSERT(cnt + vk <= UINT32_MAX);
vk += WINPR_ASSERTING_INT_CAST(uint32_t, cnt);
}
BitStream_Shift(bs, (vk % 32));
@@ -401,7 +403,8 @@ int rfx_rlgr_decode(RLGR_MODE mode, const BYTE* WINPR_RESTRICT pSrcData, UINT32
if (cnt > nbits)
cnt = nbits;
vk += cnt;
WINPR_ASSERT(cnt + vk <= UINT32_MAX);
vk += WINPR_ASSERTING_INT_CAST(uint32_t, cnt);
}
BitStream_Shift(bs, (vk % 32));

View File

@@ -808,7 +808,7 @@ static int xcrush_decompress_l1(XCRUSH_CONTEXT* WINPR_RESTRICT xcrush,
UINT16 MatchIndex = 0;
BYTE* OutputPtr = NULL;
size_t OutputLength = 0;
UINT32 OutputOffset = 0;
size_t OutputOffset = 0;
BYTE* HistoryPtr = NULL;
BYTE* HistoryBuffer = NULL;
BYTE* HistoryBufferEnd = NULL;

View File

@@ -156,7 +156,8 @@ static INLINE void zgfx_history_buffer_ring_write(ZGFX_CONTEXT* WINPR_RESTRICT z
{
CopyMemory(&(zgfx->HistoryBuffer[zgfx->HistoryIndex]), src, count);
if ((zgfx->HistoryIndex += count) == zgfx->HistoryBufferSize)
zgfx->HistoryIndex += WINPR_ASSERTING_INT_CAST(uint32_t, count);
if (zgfx->HistoryIndex == zgfx->HistoryBufferSize)
zgfx->HistoryIndex = 0;
}
else

View File

@@ -2890,6 +2890,35 @@ static BOOL rdp_write_surface_commands_capability_set(wStream* s, const rdpSetti
return rdp_capability_set_finish(s, header, CAPSET_TYPE_SURFACE_COMMANDS);
}
static bool sUuidEqual(const UUID* Uuid1, const UUID* Uuid2)
{
if (!Uuid1 && !Uuid2)
return false;
if (!Uuid2 && Uuid1)
return false;
if (!Uuid1 && !Uuid2)
return true;
if (Uuid1->Data1 != Uuid2->Data1)
return false;
if (Uuid1->Data2 != Uuid2->Data2)
return false;
if (Uuid1->Data3 != Uuid2->Data3)
return false;
for (int index = 0; index < 8; index++)
{
if (Uuid1->Data4[index] != Uuid2->Data4[index])
return false;
}
return true;
}
#ifdef WITH_DEBUG_CAPABILITIES
static BOOL rdp_print_surface_commands_capability_set(wStream* s)
{
@@ -2921,20 +2950,18 @@ static void rdp_print_bitmap_codec_guid(const GUID* guid)
static char* rdp_get_bitmap_codec_guid_name(const GUID* guid)
{
RPC_STATUS rpc_status = 0;
WINPR_ASSERT(guid);
if (UuidEqual(guid, &CODEC_GUID_REMOTEFX, &rpc_status))
if (sUuidEqual(guid, &CODEC_GUID_REMOTEFX))
return "CODEC_GUID_REMOTEFX";
else if (UuidEqual(guid, &CODEC_GUID_NSCODEC, &rpc_status))
else if (sUuidEqual(guid, &CODEC_GUID_NSCODEC))
return "CODEC_GUID_NSCODEC";
else if (UuidEqual(guid, &CODEC_GUID_IGNORE, &rpc_status))
else if (sUuidEqual(guid, &CODEC_GUID_IGNORE))
return "CODEC_GUID_IGNORE";
else if (UuidEqual(guid, &CODEC_GUID_IMAGE_REMOTEFX, &rpc_status))
else if (sUuidEqual(guid, &CODEC_GUID_IMAGE_REMOTEFX))
return "CODEC_GUID_IMAGE_REMOTEFX";
#if defined(WITH_JPEG)
else if (UuidEqual(guid, &CODEC_GUID_JPEG, &rpc_status))
else if (sUuidEqual(guid, &CODEC_GUID_JPEG))
return "CODEC_GUID_JPEG";
#endif
@@ -3300,7 +3327,6 @@ static BOOL rdp_read_bitmap_codecs_capability_set(wStream* s, rdpSettings* setti
{
BYTE codecId = 0;
GUID codecGuid = { 0 };
RPC_STATUS rpc_status = 0;
BYTE bitmapCodecCount = 0;
UINT16 codecPropertiesLength = 0;
@@ -3331,21 +3357,21 @@ static BOOL rdp_read_bitmap_codecs_capability_set(wStream* s, rdpSettings* setti
if (isServer)
{
if (UuidEqual(&codecGuid, &CODEC_GUID_REMOTEFX, &rpc_status))
if (sUuidEqual(&codecGuid, &CODEC_GUID_REMOTEFX))
{
guidRemoteFx = TRUE;
settings->RemoteFxCodecId = codecId;
if (!rdp_read_codec_ts_rfx_clnt_caps_container(sub, settings))
return FALSE;
}
else if (UuidEqual(&codecGuid, &CODEC_GUID_IMAGE_REMOTEFX, &rpc_status))
else if (sUuidEqual(&codecGuid, &CODEC_GUID_IMAGE_REMOTEFX))
{
/* Microsoft RDP servers ignore CODEC_GUID_IMAGE_REMOTEFX codec properties */
guidRemoteFxImage = TRUE;
if (!Stream_SafeSeek(sub, codecPropertiesLength)) /* codecProperties */
return FALSE;
}
else if (UuidEqual(&codecGuid, &CODEC_GUID_NSCODEC, &rpc_status))
else if (sUuidEqual(&codecGuid, &CODEC_GUID_NSCODEC))
{
BYTE colorLossLevel = 0;
BYTE fAllowSubsampling = 0;
@@ -3368,7 +3394,7 @@ static BOOL rdp_read_bitmap_codecs_capability_set(wStream* s, rdpSettings* setti
settings->NSCodecAllowSubsampling = fAllowSubsampling;
settings->NSCodecColorLossLevel = colorLossLevel;
}
else if (UuidEqual(&codecGuid, &CODEC_GUID_IGNORE, &rpc_status))
else if (sUuidEqual(&codecGuid, &CODEC_GUID_IGNORE))
{
if (!Stream_SafeSeek(sub, codecPropertiesLength)) /* codecProperties */
return FALSE;

View File

@@ -849,7 +849,7 @@ static BOOL http_response_parse_header_field(HttpResponse* response, const char*
if ((errno != 0) || (val > INT32_MAX))
return FALSE;
response->ContentLength = val;
response->ContentLength = WINPR_ASSERTING_INT_CAST(size_t, val);
}
else if (_stricmp(name, "Content-Type") == 0)
{

View File

@@ -1116,7 +1116,7 @@ BOOL rpc_client_write_call(rdpRpc* rpc, wStream* s, UINT16 opnum)
CopyMemory(&buffer[offset], &request_pdu.auth_verifier.auth_type, 8);
offset += 8;
if (offset > UINT32_MAX)
if (offset > request_pdu.header.frag_length)
goto fail;
plaintext.pvBuffer = buffer;

View File

@@ -98,14 +98,16 @@ static
*flags = STREAM_MSG_SRV_RX;
else
*flags = STREAM_MSG_SRV_TX;
if (!Stream_EnsureRemainingCapacity(s, size))
const size_t usize = WINPR_ASSERTING_INT_CAST(size_t, size);
if (!Stream_EnsureRemainingCapacity(s, usize))
goto fail;
r = fread(Stream_Pointer(s), 1, size, fp);
r = fread(Stream_Pointer(s), 1, usize, fp);
if (r != size)
goto fail;
if (crc32 != crc32b(Stream_ConstPointer(s), size))
if (crc32 != crc32b(Stream_ConstPointer(s), usize))
goto fail;
Stream_Seek(s, size);
Stream_Seek(s, usize);
if (pOffset)
{
@@ -133,13 +135,14 @@ static
BOOL rc = FALSE;
const UINT64 t = GetTickCount64();
const BYTE* data = Stream_Buffer(s);
const UINT64 size = Stream_Length(s);
const size_t usize = Stream_Length(s);
const uint64_t size = (uint64_t)usize;
if (!fp || !s)
return FALSE;
{
const UINT32 crc32 = crc32b(data, size);
const UINT32 crc32 = crc32b(data, usize);
const BYTE received = flags & STREAM_MSG_SRV_RX;
size_t r = fwrite(&t, 1, sizeof(t), fp);
if (r != sizeof(t))
@@ -153,8 +156,8 @@ static
r = fwrite(&size, 1, sizeof(size), fp);
if (r != sizeof(size))
goto fail;
r = fwrite(data, 1, size, fp);
if (r != size)
r = fwrite(data, 1, usize, fp);
if (r != usize)
goto fail;
}
@@ -217,10 +220,17 @@ SSIZE_T stream_dump_append(const rdpContext* context, UINT32 flags, wStream* s,
if (!stream_dump_write_line(fp, flags, s))
goto fail;
rc = _ftelli64(fp);
if (rc < 0)
goto fail;
{
const int64_t rt = _ftelli64(fp);
if (rt < 0)
{
rc = -1;
goto fail;
}
rc = WINPR_ASSERTING_INT_CAST(SSIZE_T, rt);
}
*offset = (size_t)rc;
fail:
if (fp)
(void)fclose(fp);
@@ -246,7 +256,10 @@ SSIZE_T stream_dump_get(const rdpContext* context, UINT32* flags, wStream* s, si
if (!stream_dump_read_line(fp, s, pts, offset, flags))
goto fail;
rc = _ftelli64(fp);
const int64_t rt = _ftelli64(fp);
if (rt < 0)
goto fail;
rc = WINPR_ASSERTING_INT_CAST(SSIZE_T, rt);
fail:
if (fp)
(void)fclose(fp);
@@ -364,7 +377,7 @@ static int stream_dump_replay_transport_read(rdpTransport* transport, wStream* s
if (slp > 0)
{
size_t duration = slp;
uint64_t duration = slp;
do
{
const DWORD actual = (DWORD)MIN(duration, UINT32_MAX);

View File

@@ -2136,7 +2136,8 @@ static BOOL update_send_create_offscreen_bitmap_order(
const size_t em = Stream_GetPosition(s);
Stream_SetPosition(s, bm);
Stream_Write_UINT8(s, controlFlags); /* controlFlags (1 byte) */
Stream_Write_UINT8(s,
WINPR_ASSERTING_INT_CAST(uint8_t, controlFlags)); /* controlFlags (1 byte) */
Stream_SetPosition(s, em);
update->numberOrders++;
return TRUE;
@@ -2173,7 +2174,8 @@ static BOOL update_send_switch_surface_order(rdpContext* context,
const size_t em = Stream_GetPosition(s);
Stream_SetPosition(s, bm);
Stream_Write_UINT8(s, controlFlags); /* controlFlags (1 byte) */
Stream_Write_UINT8(s,
WINPR_ASSERTING_INT_CAST(uint8_t, controlFlags)); /* controlFlags (1 byte) */
Stream_SetPosition(s, em);
update->numberOrders++;
return TRUE;

View File

@@ -997,7 +997,8 @@ static BOOL update_recv_notification_icon_info_order(rdpUpdate* update, wStream*
return result;
}
static BOOL update_read_desktop_actively_monitored_order(wStream* s, WINDOW_ORDER_INFO* orderInfo,
static BOOL update_read_desktop_actively_monitored_order(wStream* s,
const WINDOW_ORDER_INFO* orderInfo,
MONITORED_DESKTOP_ORDER* monitored_desktop)
{
if (orderInfo->fieldFlags & WINDOW_ORDER_FIELD_DESKTOP_ACTIVE_WND)
@@ -1016,7 +1017,10 @@ static BOOL update_read_desktop_actively_monitored_order(wStream* s, WINDOW_ORDE
Stream_Read_UINT8(s, monitored_desktop->numWindowIds); /* numWindowIds (1 byte) */
if (!Stream_CheckAndLogRequiredLengthOfSize(TAG, s, monitored_desktop->numWindowIds, 4ull))
{
monitored_desktop->numWindowIds = 0;
return FALSE;
}
if (monitored_desktop->numWindowIds > 0)
{
@@ -1027,6 +1031,7 @@ static BOOL update_read_desktop_actively_monitored_order(wStream* s, WINDOW_ORDE
{
free(monitored_desktop->windowIds);
monitored_desktop->windowIds = NULL;
monitored_desktop->numWindowIds = 0;
return FALSE;
}

View File

@@ -461,7 +461,7 @@ static BOOL vgids_prepare_certificate(const rdpCertificate* cert, BYTE** kxc, DW
size_t certSize = 0;
BYTE* certData = freerdp_certificate_get_der(cert, &certSize);
if (!certData || (certSize == 0))
if (!certData || (certSize == 0) || (certSize > UINT16_MAX))
{
WLog_ERR(TAG, "Failed to get certificate size");
goto handle_error;
@@ -475,8 +475,9 @@ static BOOL vgids_prepare_certificate(const rdpCertificate* cert, BYTE** kxc, DW
}
/* compress certificate data */
destSize = certSize;
if (compress(comprData, &destSize, certData, certSize) != Z_OK)
destSize = WINPR_ASSERTING_INT_CAST(uint16_t, certSize);
if (compress(comprData, &destSize, certData, WINPR_ASSERTING_INT_CAST(uint16_t, certSize)) !=
Z_OK)
{
WLog_ERR(TAG, "Failed to compress certificate data");
goto handle_error;
@@ -485,7 +486,7 @@ static BOOL vgids_prepare_certificate(const rdpCertificate* cert, BYTE** kxc, DW
/* Write container data */
s = Stream_New(NULL, destSize + 4);
Stream_Write_UINT16(s, 0x0001);
Stream_Write_UINT16(s, (UINT16)certSize);
Stream_Write_UINT16(s, WINPR_ASSERTING_INT_CAST(uint16_t, certSize));
Stream_Write(s, comprData, destSize);
Stream_SealLength(s);

View File

@@ -147,23 +147,23 @@ static INLINE pstatus_t generic_image_copy_bgr24_bgrx32(BYTE* WINPR_RESTRICT pDs
UINT32 nWidth, UINT32 nHeight,
const BYTE* WINPR_RESTRICT pSrcData,
UINT32 nSrcStep, UINT32 nXSrc, UINT32 nYSrc,
SSIZE_T srcVMultiplier, SSIZE_T srcVOffset,
SSIZE_T dstVMultiplier, SSIZE_T dstVOffset)
int64_t srcVMultiplier, int64_t srcVOffset,
int64_t dstVMultiplier, int64_t dstVOffset)
{
const SSIZE_T srcByte = 3;
const SSIZE_T dstByte = 4;
const int64_t srcByte = 3;
const int64_t dstByte = 4;
const UINT32 width = nWidth - nWidth % 8;
for (SSIZE_T y = 0; y < nHeight; y++)
for (int64_t y = 0; y < nHeight; y++)
{
const BYTE* WINPR_RESTRICT srcLine =
&pSrcData[srcVMultiplier * (y + nYSrc) * nSrcStep + srcVOffset];
BYTE* WINPR_RESTRICT dstLine =
&pDstData[dstVMultiplier * (y + nYDst) * nDstStep + dstVOffset];
SSIZE_T x = 0;
int64_t x = 0;
WINPR_PRAGMA_UNROLL_LOOP
for (; x < width; x++)
{
@@ -186,23 +186,23 @@ static INLINE pstatus_t generic_image_copy_bgr24_bgrx32(BYTE* WINPR_RESTRICT pDs
static INLINE pstatus_t generic_image_copy_bgrx32_bgrx32(
BYTE* WINPR_RESTRICT pDstData, UINT32 nDstStep, UINT32 nXDst, UINT32 nYDst, UINT32 nWidth,
UINT32 nHeight, const BYTE* WINPR_RESTRICT pSrcData, UINT32 nSrcStep, UINT32 nXSrc,
UINT32 nYSrc, SSIZE_T srcVMultiplier, SSIZE_T srcVOffset, SSIZE_T dstVMultiplier,
SSIZE_T dstVOffset)
UINT32 nYSrc, int64_t srcVMultiplier, int64_t srcVOffset, int64_t dstVMultiplier,
int64_t dstVOffset)
{
const SSIZE_T srcByte = 4;
const SSIZE_T dstByte = 4;
const int64_t srcByte = 4;
const int64_t dstByte = 4;
const UINT32 width = nWidth - nWidth % 8;
for (SSIZE_T y = 0; y < nHeight; y++)
for (int64_t y = 0; y < nHeight; y++)
{
const BYTE* WINPR_RESTRICT srcLine =
&pSrcData[srcVMultiplier * (y + nYSrc) * nSrcStep + srcVOffset];
BYTE* WINPR_RESTRICT dstLine =
&pDstData[dstVMultiplier * (y + nYDst) * nDstStep + dstVOffset];
SSIZE_T x = 0;
int64_t x = 0;
WINPR_PRAGMA_UNROLL_LOOP
for (; x < width; x++)
{
@@ -225,20 +225,20 @@ pstatus_t generic_image_copy_no_overlap_convert(
BYTE* WINPR_RESTRICT pDstData, DWORD DstFormat, UINT32 nDstStep, UINT32 nXDst, UINT32 nYDst,
UINT32 nWidth, UINT32 nHeight, const BYTE* WINPR_RESTRICT pSrcData, DWORD SrcFormat,
UINT32 nSrcStep, UINT32 nXSrc, UINT32 nYSrc, const gdiPalette* WINPR_RESTRICT palette,
SSIZE_T srcVMultiplier, SSIZE_T srcVOffset, SSIZE_T dstVMultiplier, SSIZE_T dstVOffset)
int64_t srcVMultiplier, int64_t srcVOffset, int64_t dstVMultiplier, int64_t dstVOffset)
{
const SSIZE_T srcByte = FreeRDPGetBytesPerPixel(SrcFormat);
const SSIZE_T dstByte = FreeRDPGetBytesPerPixel(DstFormat);
const int64_t srcByte = FreeRDPGetBytesPerPixel(SrcFormat);
const int64_t dstByte = FreeRDPGetBytesPerPixel(DstFormat);
const UINT32 width = nWidth - nWidth % 8;
for (SSIZE_T y = 0; y < nHeight; y++)
for (int64_t y = 0; y < nHeight; y++)
{
const BYTE* WINPR_RESTRICT srcLine =
&pSrcData[srcVMultiplier * (y + nYSrc) * nSrcStep + srcVOffset];
BYTE* WINPR_RESTRICT dstLine =
&pDstData[dstVMultiplier * (y + nYDst) * nDstStep + dstVOffset];
SSIZE_T x = 0;
int64_t x = 0;
// WINPR_PRAGMA_UNROLL_LOOP
for (; x < width; x++)
{
@@ -260,16 +260,16 @@ pstatus_t generic_image_copy_no_overlap_memcpy(
BYTE* WINPR_RESTRICT pDstData, DWORD DstFormat, UINT32 nDstStep, UINT32 nXDst, UINT32 nYDst,
UINT32 nWidth, UINT32 nHeight, const BYTE* WINPR_RESTRICT pSrcData, DWORD SrcFormat,
UINT32 nSrcStep, UINT32 nXSrc, UINT32 nYSrc,
WINPR_ATTR_UNUSED const gdiPalette* WINPR_RESTRICT palette, SSIZE_T srcVMultiplier,
SSIZE_T srcVOffset, SSIZE_T dstVMultiplier, SSIZE_T dstVOffset, WINPR_ATTR_UNUSED UINT32 flags)
WINPR_ATTR_UNUSED const gdiPalette* WINPR_RESTRICT palette, int64_t srcVMultiplier,
int64_t srcVOffset, int64_t dstVMultiplier, int64_t dstVOffset, WINPR_ATTR_UNUSED UINT32 flags)
{
const SSIZE_T dstByte = FreeRDPGetBytesPerPixel(DstFormat);
const SSIZE_T srcByte = FreeRDPGetBytesPerPixel(SrcFormat);
const SSIZE_T copyDstWidth = nWidth * dstByte;
const SSIZE_T xSrcOffset = nXSrc * srcByte;
const SSIZE_T xDstOffset = nXDst * dstByte;
const int64_t dstByte = FreeRDPGetBytesPerPixel(DstFormat);
const int64_t srcByte = FreeRDPGetBytesPerPixel(SrcFormat);
const int64_t copyDstWidth = nWidth * dstByte;
const int64_t xSrcOffset = nXSrc * srcByte;
const int64_t xDstOffset = nXDst * dstByte;
for (SSIZE_T y = 0; y < nHeight; y++)
for (int64_t y = 0; y < nHeight; y++)
{
const BYTE* WINPR_RESTRICT srcLine =
&pSrcData[srcVMultiplier * (y + nYSrc) * nSrcStep + srcVOffset];
@@ -286,7 +286,7 @@ static INLINE pstatus_t generic_image_copy_no_overlap_dst_alpha(
BYTE* WINPR_RESTRICT pDstData, DWORD DstFormat, UINT32 nDstStep, UINT32 nXDst, UINT32 nYDst,
UINT32 nWidth, UINT32 nHeight, const BYTE* WINPR_RESTRICT pSrcData, DWORD SrcFormat,
UINT32 nSrcStep, UINT32 nXSrc, UINT32 nYSrc, const gdiPalette* WINPR_RESTRICT palette,
SSIZE_T srcVMultiplier, SSIZE_T srcVOffset, SSIZE_T dstVMultiplier, SSIZE_T dstVOffset)
int64_t srcVMultiplier, int64_t srcVOffset, int64_t dstVMultiplier, int64_t dstVOffset)
{
WINPR_ASSERT(pDstData);
WINPR_ASSERT(pSrcData);
@@ -348,7 +348,7 @@ static INLINE pstatus_t generic_image_copy_no_overlap_no_alpha(
BYTE* WINPR_RESTRICT pDstData, DWORD DstFormat, UINT32 nDstStep, UINT32 nXDst, UINT32 nYDst,
UINT32 nWidth, UINT32 nHeight, const BYTE* WINPR_RESTRICT pSrcData, DWORD SrcFormat,
UINT32 nSrcStep, UINT32 nXSrc, UINT32 nYSrc, const gdiPalette* WINPR_RESTRICT palette,
SSIZE_T srcVMultiplier, SSIZE_T srcVOffset, SSIZE_T dstVMultiplier, SSIZE_T dstVOffset,
int64_t srcVMultiplier, int64_t srcVOffset, int64_t dstVMultiplier, int64_t dstVOffset,
UINT32 flags)
{
if (FreeRDPAreColorFormatsEqualNoAlpha(SrcFormat, DstFormat))
@@ -372,10 +372,10 @@ static pstatus_t generic_image_copy_no_overlap(BYTE* WINPR_RESTRICT pDstData, DW
UINT32 flags)
{
const BOOL vSrcVFlip = (flags & FREERDP_FLIP_VERTICAL) ? TRUE : FALSE;
SSIZE_T srcVOffset = 0;
SSIZE_T srcVMultiplier = 1;
SSIZE_T dstVOffset = 0;
SSIZE_T dstVMultiplier = 1;
int64_t srcVOffset = 0;
int64_t srcVMultiplier = 1;
int64_t dstVOffset = 0;
int64_t dstVMultiplier = 1;
if ((nWidth == 0) || (nHeight == 0))
return PRIMITIVES_SUCCESS;

View File

@@ -31,13 +31,13 @@ pstatus_t generic_image_copy_no_overlap_convert(
BYTE* WINPR_RESTRICT pDstData, DWORD DstFormat, UINT32 nDstStep, UINT32 nXDst, UINT32 nYDst,
UINT32 nWidth, UINT32 nHeight, const BYTE* WINPR_RESTRICT pSrcData, DWORD SrcFormat,
UINT32 nSrcStep, UINT32 nXSrc, UINT32 nYSrc, const gdiPalette* WINPR_RESTRICT palette,
SSIZE_T srcVMultiplier, SSIZE_T srcVOffset, SSIZE_T dstVMultiplier, SSIZE_T dstVOffset);
int64_t srcVMultiplier, int64_t srcVOffset, int64_t dstVMultiplier, int64_t dstVOffset);
pstatus_t generic_image_copy_no_overlap_memcpy(
BYTE* WINPR_RESTRICT pDstData, DWORD DstFormat, UINT32 nDstStep, UINT32 nXDst, UINT32 nYDst,
UINT32 nWidth, UINT32 nHeight, const BYTE* WINPR_RESTRICT pSrcData, DWORD SrcFormat,
UINT32 nSrcStep, UINT32 nXSrc, UINT32 nYSrc, const gdiPalette* WINPR_RESTRICT palette,
SSIZE_T srcVMultiplier, SSIZE_T srcVOffset, SSIZE_T dstVMultiplier, SSIZE_T dstVOffset,
int64_t srcVMultiplier, int64_t srcVOffset, int64_t dstVMultiplier, int64_t dstVOffset,
UINT32 flags);
FREERDP_LOCAL void primitives_init_copy_sse41_int(primitives_t* WINPR_RESTRICT prims);

View File

@@ -24,7 +24,8 @@
/* ----------------------------------------------------------------------------
* Set pDst to the sign-value of the 16-bit values in pSrc (-1, 0, or 1).
*/
static pstatus_t general_sign_16s(const INT16* pSrc, INT16* pDst, UINT32 len)
static pstatus_t general_sign_16s(const INT16* WINPR_RESTRICT pSrc, INT16* WINPR_RESTRICT pDst,
UINT32 len)
{
while (len--)
{

View File

@@ -36,20 +36,20 @@ SSE3_SSD_ROUTINE(sse3_add_16s, INT16, generic->add_16s, _mm_adds_epi16,
generic->add_16s(sptr1++, sptr2++, dptr++, 1))
static pstatus_t sse3_add_16s_inplace(INT16* WINPR_RESTRICT pSrcDst1,
INT16* WINPR_RESTRICT pSrcDst2, UINT32 len)
INT16* WINPR_RESTRICT pSrcDst2, UINT32 ulen)
{
const int shifts = 2;
INT16* dptr1 = pSrcDst1;
INT16* dptr2 = pSrcDst2;
if (len < 16) /* pointless if too small */
return generic->add_16s_inplace(pSrcDst1, pSrcDst2, len);
if (ulen < 16) /* pointless if too small */
return generic->add_16s_inplace(pSrcDst1, pSrcDst2, ulen);
UINT32 offBeatMask = (1 << (shifts - 1)) - 1;
if ((ULONG_PTR)pSrcDst1 & offBeatMask)
{
/* Incrementing the pointer skips over 16-byte boundary. */
return generic->add_16s_inplace(pSrcDst1, pSrcDst2, len);
return generic->add_16s_inplace(pSrcDst1, pSrcDst2, ulen);
}
/* Get to the 16-byte boundary now. */
const size_t rem = ((UINT_PTR)dptr1 & 0xf) / sizeof(INT16);
@@ -63,6 +63,7 @@ static pstatus_t sse3_add_16s_inplace(INT16* WINPR_RESTRICT pSrcDst1,
dptr2 += add;
}
/* Use 4 128-bit SSE registers. */
size_t len = ulen;
size_t count = len >> (7 - shifts);
len -= count << (7 - shifts);
if (((const ULONG_PTR)dptr1 & 0x0f) || ((const ULONG_PTR)dptr2 & 0x0f))
@@ -164,7 +165,7 @@ static pstatus_t sse3_add_16s_inplace(INT16* WINPR_RESTRICT pSrcDst1,
}
/* Finish off the remainder. */
if (len > 0)
return generic->add_16s_inplace(dptr1, dptr2, len);
return generic->add_16s_inplace(dptr1, dptr2, WINPR_ASSERTING_INT_CAST(uint32_t, len));
return PRIMITIVES_SUCCESS;
}

View File

@@ -44,12 +44,12 @@ static INLINE pstatus_t avx2_image_copy_bgr24_bgrx32(BYTE* WINPR_RESTRICT pDstDa
UINT32 nHeight,
const BYTE* WINPR_RESTRICT pSrcData,
UINT32 nSrcStep, UINT32 nXSrc, UINT32 nYSrc,
SSIZE_T srcVMultiplier, SSIZE_T srcVOffset,
SSIZE_T dstVMultiplier, SSIZE_T dstVOffset)
int64_t srcVMultiplier, int64_t srcVOffset,
int64_t dstVMultiplier, int64_t dstVOffset)
{
const SSIZE_T srcByte = 3;
const SSIZE_T dstByte = 4;
const int64_t srcByte = 3;
const int64_t dstByte = 4;
const __m256i mask = mm256_set_epu32(0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000,
0xFF000000, 0xFF000000, 0xFF000000);
@@ -58,16 +58,16 @@ static INLINE pstatus_t avx2_image_copy_bgr24_bgrx32(BYTE* WINPR_RESTRICT pDstDa
const __m256i shelpmask = mm256_set_epu32(0xffffffff, 0xffffffff, 0xffffff1f, 0xff1e1d1c,
0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff);
const UINT32 rem = nWidth % 8;
const SSIZE_T width = nWidth - rem;
const int64_t width = nWidth - rem;
for (SSIZE_T y = 0; y < nHeight; y++)
for (int64_t y = 0; y < nHeight; y++)
{
const BYTE* WINPR_RESTRICT srcLine =
&pSrcData[srcVMultiplier * (y + nYSrc) * nSrcStep + srcVOffset];
BYTE* WINPR_RESTRICT dstLine =
&pDstData[dstVMultiplier * (y + nYDst) * nDstStep + dstVOffset];
SSIZE_T x = 0;
int64_t x = 0;
/* Ensure alignment requirements can be met */
for (; x < width; x += 8)
@@ -108,12 +108,12 @@ static INLINE pstatus_t avx2_image_copy_bgrx32_bgrx32(BYTE* WINPR_RESTRICT pDstD
UINT32 nWidth, UINT32 nHeight,
const BYTE* WINPR_RESTRICT pSrcData,
UINT32 nSrcStep, UINT32 nXSrc, UINT32 nYSrc,
SSIZE_T srcVMultiplier, SSIZE_T srcVOffset,
SSIZE_T dstVMultiplier, SSIZE_T dstVOffset)
int64_t srcVMultiplier, int64_t srcVOffset,
int64_t dstVMultiplier, int64_t dstVOffset)
{
const SSIZE_T srcByte = 4;
const SSIZE_T dstByte = 4;
const int64_t srcByte = 4;
const int64_t dstByte = 4;
const __m256i mask = _mm256_setr_epi8(
(char)0xFF, (char)0xFF, (char)0xFF, 0x00, (char)0xFF, (char)0xFF, (char)0xFF, 0x00,
@@ -121,15 +121,15 @@ static INLINE pstatus_t avx2_image_copy_bgrx32_bgrx32(BYTE* WINPR_RESTRICT pDstD
(char)0xFF, (char)0xFF, (char)0xFF, 0x00, (char)0xFF, (char)0xFF, (char)0xFF, 0x00,
(char)0xFF, (char)0xFF, (char)0xFF, 0x00, (char)0xFF, (char)0xFF, (char)0xFF, 0x00);
const UINT32 rem = nWidth % 8;
const SSIZE_T width = nWidth - rem;
for (SSIZE_T y = 0; y < nHeight; y++)
const int64_t width = nWidth - rem;
for (int64_t y = 0; y < nHeight; y++)
{
const BYTE* WINPR_RESTRICT srcLine =
&pSrcData[srcVMultiplier * (y + nYSrc) * nSrcStep + srcVOffset];
BYTE* WINPR_RESTRICT dstLine =
&pDstData[dstVMultiplier * (y + nYDst) * nDstStep + dstVOffset];
SSIZE_T x = 0;
int64_t x = 0;
for (; x < width; x += 8)
{
const __m256i* src = (const __m256i*)&srcLine[(x + nXSrc) * srcByte];
@@ -157,8 +157,8 @@ static pstatus_t avx2_image_copy_no_overlap_dst_alpha(
BYTE* WINPR_RESTRICT pDstData, DWORD DstFormat, UINT32 nDstStep, UINT32 nXDst, UINT32 nYDst,
UINT32 nWidth, UINT32 nHeight, const BYTE* WINPR_RESTRICT pSrcData, DWORD SrcFormat,
UINT32 nSrcStep, UINT32 nXSrc, UINT32 nYSrc, const gdiPalette* WINPR_RESTRICT palette,
UINT32 flags, SSIZE_T srcVMultiplier, SSIZE_T srcVOffset, SSIZE_T dstVMultiplier,
SSIZE_T dstVOffset)
UINT32 flags, int64_t srcVMultiplier, int64_t srcVOffset, int64_t dstVMultiplier,
int64_t dstVOffset)
{
WINPR_ASSERT(pDstData);
WINPR_ASSERT(pSrcData);
@@ -220,10 +220,10 @@ static pstatus_t avx2_image_copy_no_overlap(BYTE* WINPR_RESTRICT pDstData, DWORD
const gdiPalette* WINPR_RESTRICT palette, UINT32 flags)
{
const BOOL vSrcVFlip = (flags & FREERDP_FLIP_VERTICAL) ? TRUE : FALSE;
SSIZE_T srcVOffset = 0;
SSIZE_T srcVMultiplier = 1;
SSIZE_T dstVOffset = 0;
SSIZE_T dstVMultiplier = 1;
int64_t srcVOffset = 0;
int64_t srcVMultiplier = 1;
int64_t dstVOffset = 0;
int64_t dstVMultiplier = 1;
if ((nWidth == 0) || (nHeight == 0))
return PRIMITIVES_SUCCESS;

View File

@@ -38,26 +38,26 @@ static INLINE pstatus_t sse_image_copy_bgr24_bgrx32(BYTE* WINPR_RESTRICT pDstDat
UINT32 nHeight,
const BYTE* WINPR_RESTRICT pSrcData,
UINT32 nSrcStep, UINT32 nXSrc, UINT32 nYSrc,
SSIZE_T srcVMultiplier, SSIZE_T srcVOffset,
SSIZE_T dstVMultiplier, SSIZE_T dstVOffset)
int64_t srcVMultiplier, int64_t srcVOffset,
int64_t dstVMultiplier, int64_t dstVOffset)
{
const SSIZE_T srcByte = 3;
const SSIZE_T dstByte = 4;
const int64_t srcByte = 3;
const int64_t dstByte = 4;
const __m128i mask = mm_set_epu32(0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000);
const __m128i smask = mm_set_epu32(0xff0b0a09, 0xff080706, 0xff050403, 0xff020100);
const UINT32 rem = nWidth % 4;
const SSIZE_T width = nWidth - rem;
for (SSIZE_T y = 0; y < nHeight; y++)
const int64_t width = nWidth - rem;
for (int64_t y = 0; y < nHeight; y++)
{
const BYTE* WINPR_RESTRICT srcLine =
&pSrcData[srcVMultiplier * (y + nYSrc) * nSrcStep + srcVOffset];
BYTE* WINPR_RESTRICT dstLine =
&pDstData[dstVMultiplier * (y + nYDst) * nDstStep + dstVOffset];
SSIZE_T x = 0;
int64_t x = 0;
/* Ensure alignment requirements can be met */
for (; x < width; x += 4)
{
@@ -89,26 +89,26 @@ static INLINE pstatus_t sse_image_copy_bgrx32_bgrx32(BYTE* WINPR_RESTRICT pDstDa
UINT32 nHeight,
const BYTE* WINPR_RESTRICT pSrcData,
UINT32 nSrcStep, UINT32 nXSrc, UINT32 nYSrc,
SSIZE_T srcVMultiplier, SSIZE_T srcVOffset,
SSIZE_T dstVMultiplier, SSIZE_T dstVOffset)
int64_t srcVMultiplier, int64_t srcVOffset,
int64_t dstVMultiplier, int64_t dstVOffset)
{
const SSIZE_T srcByte = 4;
const SSIZE_T dstByte = 4;
const int64_t srcByte = 4;
const int64_t dstByte = 4;
const __m128i mask = _mm_setr_epi8((char)0xFF, (char)0xFF, (char)0xFF, 0x00, (char)0xFF,
(char)0xFF, (char)0xFF, 0x00, (char)0xFF, (char)0xFF,
(char)0xFF, 0x00, (char)0xFF, (char)0xFF, (char)0xFF, 0x00);
const UINT32 rem = nWidth % 4;
const SSIZE_T width = nWidth - rem;
for (SSIZE_T y = 0; y < nHeight; y++)
const int64_t width = nWidth - rem;
for (int64_t y = 0; y < nHeight; y++)
{
const BYTE* WINPR_RESTRICT srcLine =
&pSrcData[srcVMultiplier * (y + nYSrc) * nSrcStep + srcVOffset];
BYTE* WINPR_RESTRICT dstLine =
&pDstData[dstVMultiplier * (y + nYDst) * nDstStep + dstVOffset];
SSIZE_T x = 0;
int64_t x = 0;
for (; x < width; x += 4)
{
const __m128i* src = (const __m128i*)&srcLine[(x + nXSrc) * srcByte];
@@ -136,8 +136,8 @@ static pstatus_t sse_image_copy_no_overlap_dst_alpha(
BYTE* WINPR_RESTRICT pDstData, DWORD DstFormat, UINT32 nDstStep, UINT32 nXDst, UINT32 nYDst,
UINT32 nWidth, UINT32 nHeight, const BYTE* WINPR_RESTRICT pSrcData, DWORD SrcFormat,
UINT32 nSrcStep, UINT32 nXSrc, UINT32 nYSrc, const gdiPalette* WINPR_RESTRICT palette,
UINT32 flags, SSIZE_T srcVMultiplier, SSIZE_T srcVOffset, SSIZE_T dstVMultiplier,
SSIZE_T dstVOffset)
UINT32 flags, int64_t srcVMultiplier, int64_t srcVOffset, int64_t dstVMultiplier,
int64_t dstVOffset)
{
WINPR_ASSERT(pDstData);
WINPR_ASSERT(pSrcData);
@@ -199,10 +199,10 @@ static pstatus_t sse_image_copy_no_overlap(BYTE* WINPR_RESTRICT pDstData, DWORD
const gdiPalette* WINPR_RESTRICT palette, UINT32 flags)
{
const BOOL vSrcVFlip = (flags & FREERDP_FLIP_VERTICAL) ? TRUE : FALSE;
SSIZE_T srcVOffset = 0;
SSIZE_T srcVMultiplier = 1;
SSIZE_T dstVOffset = 0;
SSIZE_T dstVMultiplier = 1;
int64_t srcVOffset = 0;
int64_t srcVMultiplier = 1;
int64_t dstVOffset = 0;
int64_t dstVMultiplier = 1;
if ((nWidth == 0) || (nHeight == 0))
return PRIMITIVES_SUCCESS;

View File

@@ -43,21 +43,22 @@ SSE3_SCD_ROUTINE(sse2_lShiftC_16u, UINT16, generic->lShiftC_16u, _mm_slli_epi16,
SSE3_SCD_ROUTINE(sse2_rShiftC_16u, UINT16, generic->rShiftC_16u, _mm_srli_epi16, int16_t,
*dptr++ = *sptr++ >> val)
static pstatus_t sse2_lShiftC_16s_inplace(INT16* WINPR_RESTRICT pSrcDst, UINT32 val, UINT32 len)
static pstatus_t sse2_lShiftC_16s_inplace(INT16* WINPR_RESTRICT pSrcDst, UINT32 val, UINT32 ulen)
{
size_t len = ulen;
const INT32 shifts = 2;
if (val == 0)
return PRIMITIVES_SUCCESS;
if (val >= 16)
return -1;
if (len < 16) /* pointless if too small */
return generic->lShiftC_16s_inplace(pSrcDst, val, len);
return generic->lShiftC_16s_inplace(pSrcDst, val, ulen);
UINT32 offBeatMask = (1 << (shifts - 1)) - 1;
if ((ULONG_PTR)pSrcDst & offBeatMask)
{
/* Incrementing the pointer skips over 16-byte boundary. */
return generic->lShiftC_16s_inplace(pSrcDst, val, len);
return generic->lShiftC_16s_inplace(pSrcDst, val, ulen);
}
/* Get to the 16-byte boundary now. */
const UINT32 rem = ((UINT_PTR)pSrcDst & 0x0f) / sizeof(INT16);
@@ -72,7 +73,7 @@ static pstatus_t sse2_lShiftC_16s_inplace(INT16* WINPR_RESTRICT pSrcDst, UINT32
}
/* Use 8 128-bit SSE registers. */
uint32_t count = len >> (8 - shifts);
size_t count = len >> (8 - shifts);
len -= count << (8 - shifts);
while (count--)
@@ -128,7 +129,7 @@ static pstatus_t sse2_lShiftC_16s_inplace(INT16* WINPR_RESTRICT pSrcDst, UINT32
/* Finish off the remainder. */
if (len > 0)
return generic->lShiftC_16s_inplace(pSrcDst, val, len);
return generic->lShiftC_16s_inplace(pSrcDst, val, WINPR_ASSERTING_INT_CAST(uint32_t, len));
return PRIMITIVES_SUCCESS;
}

View File

@@ -201,8 +201,9 @@
#define SSE3_SSD_ROUTINE(_name_, _type_, _fallback_, _op_, _slowWay_) \
static pstatus_t _name_(const _type_* WINPR_RESTRICT pSrc1, \
const _type_* WINPR_RESTRICT pSrc2, _type_* WINPR_RESTRICT pDst, \
UINT32 len) \
UINT32 ulen) \
{ \
size_t len = ulen; \
int shifts = 0; \
const _type_* sptr1 = pSrc1; \
const _type_* sptr2 = pSrc2; \

View File

@@ -511,7 +511,7 @@ static PfChannelResult DynvcTrackerPeekFn(ChannelStateTracker* tracker, BOOL fir
size_t extraSize = Stream_GetRemainingLength(s);
trackerState->CurrentDataFragments++;
trackerState->CurrentDataReceived += extraSize;
trackerState->CurrentDataReceived += WINPR_ASSERTING_INT_CAST(uint32_t, extraSize);
if (dynChannel->packetReassembly)
{

View File

@@ -1078,7 +1078,7 @@ static BOOL pf_channel_rdpdr_rewrite_device_list_to(wStream* s, UINT32 fromVersi
const size_t datalen = charCount * sizeof(WCHAR);
if (!Stream_EnsureRemainingCapacity(s, datalen + sizeof(UINT32)))
goto fail;
Stream_Write_UINT32(s, datalen);
Stream_Write_UINT32(s, WINPR_ASSERTING_INT_CAST(uint32_t, datalen));
const SSIZE_T rcw = Stream_Write_UTF16_String_From_UTF8(
s, charCount, device.PreferredDosName, charCount - 1, TRUE);

View File

@@ -256,7 +256,7 @@ void* UwacClipboardDataGet(UwacSeat* seat, const char* mime, size_t* size)
data = tmp;
if (pos > alloc)
if (pos >= alloc)
goto fail;
r = read(pipefd[0], &data[pos], alloc - pos);

View File

@@ -59,6 +59,7 @@
#include <stdio.h>
#include <string.h>
#include <sys/epoll.h>
#include <sys/stat.h>
#include <uwac/config.h>
@@ -178,6 +179,14 @@ int uwac_os_epoll_create_cloexec(void)
return set_cloexec_or_close(fd);
}
static int secure_mkstemp(char* tmpname)
{
const mode_t mask = umask(S_IRWXU);
int fd = mkstemp(tmpname);
(void)umask(mask);
return fd;
}
static int create_tmpfile_cloexec(char* tmpname)
{
int fd = 0;
@@ -190,7 +199,7 @@ static int create_tmpfile_cloexec(char* tmpname)
unlink(tmpname);
#else
fd = mkstemp(tmpname);
fd = secure_mkstemp(tmpname);
if (fd >= 0)
{

View File

@@ -581,7 +581,9 @@ static BOOL process_files(wClipboard* clipboard, const char* data, UINT32 pSize,
if (strncmp(data, prefix, prefix_len) != 0)
return FALSE;
data += prefix_len;
pSize -= prefix_len;
if (pSize < prefix_len)
return FALSE;
pSize -= WINPR_ASSERTING_INT_CAST(uint32_t, prefix_len);
BOOL rc = FALSE;
char* copy = strndup(data, pSize);
@@ -592,10 +594,12 @@ static BOOL process_files(wClipboard* clipboard, const char* data, UINT32 pSize,
char* tok = strtok_s(copy, "\n", &endptr);
while (tok)
{
size_t tok_len = strnlen(tok, pSize);
const size_t tok_len = strnlen(tok, pSize);
if (!process_uri(clipboard, tok, tok_len))
goto fail;
pSize -= tok_len;
if (pSize < tok_len)
goto fail;
pSize -= WINPR_ASSERTING_INT_CAST(uint32_t, tok_len);
tok = strtok_s(NULL, "\n", &endptr);
}
rc = TRUE;

View File

@@ -5,6 +5,22 @@
#include <winpr/file.h>
#include <winpr/windows.h>
#if !defined(_WIN32)
#include <sys/stat.h>
#endif
static int secure_mkstemp(char* tmpname)
{
#if !defined(_WIN32)
const mode_t mask = umask(S_IRWXU);
#endif
int fd = mkstemp(tmpname);
#if !defined(_WIN32)
(void)umask(mask);
#endif
return fd;
}
int TestFileDeleteFile(int argc, char* argv[])
{
BOOL rc = FALSE;
@@ -28,7 +44,7 @@ int TestFileDeleteFile(int argc, char* argv[])
if (rc)
return -1;
fd = mkstemp(validA);
fd = secure_mkstemp(validA);
if (fd < 0)
return -1;
@@ -36,7 +52,7 @@ int TestFileDeleteFile(int argc, char* argv[])
if (!rc)
return -1;
fd = mkstemp(validW);
fd = secure_mkstemp(validW);
if (fd < 0)
return -1;

View File

@@ -53,13 +53,13 @@ static int SemaphoreGetFd(HANDLE handle)
static DWORD SemaphoreCleanupHandle(HANDLE handle)
{
SSIZE_T length = 0;
WINPR_SEMAPHORE* sem = (WINPR_SEMAPHORE*)handle;
if (!SemaphoreIsHandled(handle))
return WAIT_FAILED;
length = read(sem->pipe_fd[0], &length, 1);
uint8_t val = 0;
const SSIZE_T length = read(sem->pipe_fd[0], &val, sizeof(val));
if (length != 1)
{

View File

@@ -181,6 +181,7 @@ static BOOL IniFile_Load_File(wIniFile* ini, const char* filename)
goto out_file;
ini->buffer[fileSize] = '\n';
ini->buffer[fileSize + 1] = '\0';
IniFile_Load_NextLine(ini, ini->buffer);
rc = TRUE;

View File

@@ -333,13 +333,16 @@ BOOL WLog_PacketMessage_Write(wPcap* pcap, void* data, size_t length, DWORD flag
{
tcp.SequenceNumber = g_OutboundSequenceNumber;
tcp.AcknowledgementNumber = g_InboundSequenceNumber;
g_OutboundSequenceNumber += length;
WINPR_ASSERT(length + g_OutboundSequenceNumber <= UINT32_MAX);
g_OutboundSequenceNumber += WINPR_ASSERTING_INT_CAST(uint32_t, length);
}
else
{
tcp.SequenceNumber = g_InboundSequenceNumber;
tcp.AcknowledgementNumber = g_OutboundSequenceNumber;
g_InboundSequenceNumber += length;
WINPR_ASSERT(length + g_InboundSequenceNumber <= UINT32_MAX);
g_InboundSequenceNumber += WINPR_ASSERTING_INT_CAST(uint32_t, length);
}
tcp.Offset = 5;
@@ -352,8 +355,9 @@ BOOL WLog_PacketMessage_Write(wPcap* pcap, void* data, size_t length, DWORD flag
record.length = length;
const size_t offset = 14 + 20 + 20;
WINPR_ASSERT(record.length <= UINT32_MAX - offset);
record.header.incl_len = (UINT32)record.length + offset;
record.header.orig_len = (UINT32)record.length + offset;
const uint32_t rloff = WINPR_ASSERTING_INT_CAST(uint32_t, record.length + offset);
record.header.incl_len = rloff;
record.header.orig_len = rloff;
record.next = NULL;
UINT64 ns = winpr_GetUnixTimeNS();