|
|
087af1 |
From 6ed2f7d1a379f69cca102e8166d20eb5ed38652b Mon Sep 17 00:00:00 2001
|
|
|
087af1 |
From: akallabeth <akallabeth@posteo.net>
|
|
|
087af1 |
Date: Fri, 22 Apr 2022 16:27:21 +0200
|
|
|
087af1 |
Subject: [PATCH] Fixed format string for Stream_CheckAndLogRequiredLength
|
|
|
087af1 |
|
|
|
087af1 |
__LINE__ requires %d and not %PRIuz
|
|
|
087af1 |
|
|
|
087af1 |
(cherry picked from commit 74c1a006e940308b0653427d25a87ea5a24cb573)
|
|
|
087af1 |
---
|
|
|
087af1 |
winpr/include/winpr/stream.h | 14 ++++++++
|
|
|
087af1 |
winpr/libwinpr/utils/stream.c | 65 +++++++++++++++++++++++++++++++++++
|
|
|
087af1 |
2 files changed, 79 insertions(+)
|
|
|
087af1 |
|
|
|
087af1 |
diff --git a/winpr/include/winpr/stream.h b/winpr/include/winpr/stream.h
|
|
|
087af1 |
index f351eaa15..ed637f034 100644
|
|
|
087af1 |
--- a/winpr/include/winpr/stream.h
|
|
|
087af1 |
+++ b/winpr/include/winpr/stream.h
|
|
|
087af1 |
@@ -27,6 +27,8 @@
|
|
|
087af1 |
#include <winpr/wtypes.h>
|
|
|
087af1 |
#include <winpr/endian.h>
|
|
|
087af1 |
#include <winpr/synch.h>
|
|
|
087af1 |
+#include <winpr/wlog.h>
|
|
|
087af1 |
+#include <winpr/debug.h>
|
|
|
087af1 |
|
|
|
087af1 |
#ifdef __cplusplus
|
|
|
087af1 |
extern "C"
|
|
|
087af1 |
@@ -56,6 +57,19 @@ extern "C"
|
|
|
087af1 |
WINPR_API void Stream_StaticInit(wStream* s, BYTE* buffer, size_t size);
|
|
|
087af1 |
WINPR_API void Stream_Free(wStream* s, BOOL bFreeBuffer);
|
|
|
087af1 |
|
|
|
087af1 |
+#define Stream_CheckAndLogRequiredLength(tag, s, len) \
|
|
|
087af1 |
+ Stream_CheckAndLogRequiredLengthEx(tag, WLOG_WARN, s, len, "%s(%s:%d)", __FUNCTION__, \
|
|
|
087af1 |
+ __FILE__, __LINE__)
|
|
|
087af1 |
+ WINPR_API BOOL Stream_CheckAndLogRequiredLengthEx(const char* tag, DWORD level, wStream* s,
|
|
|
087af1 |
+ UINT64 len, const char* fmt, ...);
|
|
|
087af1 |
+ WINPR_API BOOL Stream_CheckAndLogRequiredLengthExVa(const char* tag, DWORD level, wStream* s,
|
|
|
087af1 |
+ UINT64 len, const char* fmt, va_list args);
|
|
|
087af1 |
+ WINPR_API BOOL Stream_CheckAndLogRequiredLengthWLogEx(wLog* log, DWORD level, wStream* s,
|
|
|
087af1 |
+ UINT64 len, const char* fmt, ...);
|
|
|
087af1 |
+ WINPR_API BOOL Stream_CheckAndLogRequiredLengthWLogExVa(wLog* log, DWORD level, wStream* s,
|
|
|
087af1 |
+ UINT64 len, const char* fmt,
|
|
|
087af1 |
+ va_list args);
|
|
|
087af1 |
+
|
|
|
087af1 |
static INLINE void Stream_Seek(wStream* s, size_t _offset)
|
|
|
087af1 |
{
|
|
|
087af1 |
s->pointer += (_offset);
|
|
|
087af1 |
diff --git a/winpr/libwinpr/utils/stream.c b/winpr/libwinpr/utils/stream.c
|
|
|
087af1 |
index 1271981b7..cc119c771 100644
|
|
|
087af1 |
--- a/winpr/libwinpr/utils/stream.c
|
|
|
087af1 |
+++ b/winpr/libwinpr/utils/stream.c
|
|
|
087af1 |
@@ -132,3 +132,68 @@ void Stream_Free(wStream* s, BOOL bFreeBuffer)
|
|
|
087af1 |
free(s);
|
|
|
087af1 |
}
|
|
|
087af1 |
}
|
|
|
087af1 |
+
|
|
|
087af1 |
+BOOL Stream_CheckAndLogRequiredLengthEx(const char* tag, DWORD level, wStream* s, UINT64 len,
|
|
|
087af1 |
+ const char* fmt, ...)
|
|
|
087af1 |
+{
|
|
|
087af1 |
+ const size_t actual = Stream_GetRemainingLength(s);
|
|
|
087af1 |
+
|
|
|
087af1 |
+ if (actual < len)
|
|
|
087af1 |
+ {
|
|
|
087af1 |
+ va_list args;
|
|
|
087af1 |
+
|
|
|
087af1 |
+ va_start(args, fmt);
|
|
|
087af1 |
+ Stream_CheckAndLogRequiredLengthExVa(tag, level, s, len, fmt, args);
|
|
|
087af1 |
+ va_end(args);
|
|
|
087af1 |
+
|
|
|
087af1 |
+ return FALSE;
|
|
|
087af1 |
+ }
|
|
|
087af1 |
+ return TRUE;
|
|
|
087af1 |
+}
|
|
|
087af1 |
+
|
|
|
087af1 |
+BOOL Stream_CheckAndLogRequiredLengthExVa(const char* tag, DWORD level, wStream* s, UINT64 len,
|
|
|
087af1 |
+ const char* fmt, va_list args)
|
|
|
087af1 |
+{
|
|
|
087af1 |
+ const size_t actual = Stream_GetRemainingLength(s);
|
|
|
087af1 |
+
|
|
|
087af1 |
+ if (actual < len)
|
|
|
087af1 |
+ return Stream_CheckAndLogRequiredLengthWLogExVa(WLog_Get(tag), level, s, len, fmt, args);
|
|
|
087af1 |
+ return TRUE;
|
|
|
087af1 |
+}
|
|
|
087af1 |
+
|
|
|
087af1 |
+BOOL Stream_CheckAndLogRequiredLengthWLogEx(wLog* log, DWORD level, wStream* s, UINT64 len,
|
|
|
087af1 |
+ const char* fmt, ...)
|
|
|
087af1 |
+{
|
|
|
087af1 |
+ const size_t actual = Stream_GetRemainingLength(s);
|
|
|
087af1 |
+
|
|
|
087af1 |
+ if (actual < len)
|
|
|
087af1 |
+ {
|
|
|
087af1 |
+ va_list args;
|
|
|
087af1 |
+
|
|
|
087af1 |
+ va_start(args, fmt);
|
|
|
087af1 |
+ Stream_CheckAndLogRequiredLengthWLogExVa(log, level, s, len, fmt, args);
|
|
|
087af1 |
+ va_end(args);
|
|
|
087af1 |
+
|
|
|
087af1 |
+ return FALSE;
|
|
|
087af1 |
+ }
|
|
|
087af1 |
+ return TRUE;
|
|
|
087af1 |
+}
|
|
|
087af1 |
+
|
|
|
087af1 |
+BOOL Stream_CheckAndLogRequiredLengthWLogExVa(wLog* log, DWORD level, wStream* s, UINT64 len,
|
|
|
087af1 |
+ const char* fmt, va_list args)
|
|
|
087af1 |
+{
|
|
|
087af1 |
+ const size_t actual = Stream_GetRemainingLength(s);
|
|
|
087af1 |
+
|
|
|
087af1 |
+ if (actual < len)
|
|
|
087af1 |
+ {
|
|
|
087af1 |
+ char prefix[1024] = { 0 };
|
|
|
087af1 |
+
|
|
|
087af1 |
+ vsnprintf(prefix, sizeof(prefix), fmt, args);
|
|
|
087af1 |
+
|
|
|
087af1 |
+ WLog_Print(log, level, "[%s] invalid length, got %" PRIuz ", require at least %" PRIu64,
|
|
|
087af1 |
+ prefix, actual, len);
|
|
|
087af1 |
+ winpr_log_backtrace_ex(log, level, 20);
|
|
|
087af1 |
+ return FALSE;
|
|
|
087af1 |
+ }
|
|
|
087af1 |
+ return TRUE;
|
|
|
087af1 |
+}
|
|
|
087af1 |
--
|
|
|
087af1 |
2.38.1
|
|
|
087af1 |
|