From 507722aca4fda0a68bfa8ff7ca761b2d2f7da32d Mon Sep 17 00:00:00 2001 From: akallabeth Date: Wed, 27 Apr 2022 21:37:48 +0200 Subject: [PATCH] Fixed snprintf return value checks --- winpr/libwinpr/utils/collections/BitStream.c | 5 ++++- winpr/libwinpr/utils/print.c | 8 +++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/winpr/libwinpr/utils/collections/BitStream.c b/winpr/libwinpr/utils/collections/BitStream.c index 997d879bf..77da58415 100644 --- a/winpr/libwinpr/utils/collections/BitStream.c +++ b/winpr/libwinpr/utils/collections/BitStream.c @@ -107,8 +107,11 @@ void BitDump(const char* tag, UINT32 level, const BYTE* buffer, UINT32 length, U { const char* str = strs[buffer[i / 8]]; const int nbits = (length - i) > 8 ? 8 : (length - i); - pos += _snprintf(&pbuffer[pos], length - pos, "%.*s ", nbits, str); + const int rc = _snprintf(&pbuffer[pos], length - pos, "%.*s ", nbits, str); + if (rc < 0) + return; + pos += (size_t)rc; if ((i % 64) == 0) { pos = 0; diff --git a/winpr/libwinpr/utils/print.c b/winpr/libwinpr/utils/print.c index 2d99c9d1d..be7a2b3f4 100644 --- a/winpr/libwinpr/utils/print.c +++ b/winpr/libwinpr/utils/print.c @@ -151,13 +151,19 @@ void winpr_CArrayDump(const char* tag, UINT32 level, const BYTE* data, size_t le pos = 0; for (i = 0; i < line; i++) - pos += _snprintf(&buffer[pos], llen - pos, "\\x%02" PRIX8 "", p[i]); + { + const int rc = _snprintf(&buffer[pos], llen - pos, "\\x%02" PRIX8 "", p[i]); + if (rc < 0) + goto fail; + pos += (size_t)rc; + } WLog_LVL(tag, level, "%s", buffer); offset += line; p += line; } +fail: free(buffer); }