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