diff --git a/channels/rdpdr/client/rdpdr_main.c b/channels/rdpdr/client/rdpdr_main.c index 9f1dd9578..b893ebc0d 100644 --- a/channels/rdpdr/client/rdpdr_main.c +++ b/channels/rdpdr/client/rdpdr_main.c @@ -737,12 +737,15 @@ static BOOL isAutomountLocation(const char* path) const char* location = automountLocations[x]; size_t length = 0; + WINPR_PRAGMA_DIAG_PUSH + WINPR_PRAGMA_DIAG_IGNORED_FORMAT_NONLITERAL if (strstr(location, "%lu")) (void)snprintf(buffer, sizeof(buffer), location, (unsigned long)uid); else if (strstr(location, "%s")) (void)snprintf(buffer, sizeof(buffer), location, uname); else (void)snprintf(buffer, sizeof(buffer), "%s", location); + WINPR_PRAGMA_DIAG_POP length = strnlen(buffer, sizeof(buffer)); diff --git a/client/SDL/SDL2/dialogs/sdl_connection_dialog.cpp b/client/SDL/SDL2/dialogs/sdl_connection_dialog.cpp index ff1395571..c4c18642d 100644 --- a/client/SDL/SDL2/dialogs/sdl_connection_dialog.cpp +++ b/client/SDL/SDL2/dialogs/sdl_connection_dialog.cpp @@ -456,7 +456,10 @@ std::string SDLConnectionDialog::print(const char* fmt, va_list ap) va_list copy; va_copy(copy, ap); + WINPR_PRAGMA_DIAG_PUSH + WINPR_PRAGMA_DIAG_IGNORED_FORMAT_NONLITERAL size = vsnprintf(res.data(), res.size(), fmt, copy); + WINPR_PRAGMA_DIAG_POP va_end(copy); } while ((size > 0) && (static_cast(size) > res.size())); diff --git a/client/SDL/SDL3/dialogs/sdl_connection_dialog.cpp b/client/SDL/SDL3/dialogs/sdl_connection_dialog.cpp index c6a6c25ae..b099890c6 100644 --- a/client/SDL/SDL3/dialogs/sdl_connection_dialog.cpp +++ b/client/SDL/SDL3/dialogs/sdl_connection_dialog.cpp @@ -455,7 +455,10 @@ std::string SDLConnectionDialog::print(const char* fmt, va_list ap) va_list copy; va_copy(copy, ap); + WINPR_PRAGMA_DIAG_PUSH + WINPR_PRAGMA_DIAG_IGNORED_FORMAT_NONLITERAL size = vsnprintf(res.data(), res.size(), fmt, copy); + WINPR_PRAGMA_DIAG_POP va_end(copy); } while ((size > 0) && (static_cast(size) > res.size())); diff --git a/libfreerdp/core/orders.c b/libfreerdp/core/orders.c index 17a227401..4b648cc5a 100644 --- a/libfreerdp/core/orders.c +++ b/libfreerdp/core/orders.c @@ -430,6 +430,8 @@ static BOOL check_primary_order_supported(wLog* log, rdpSettings* settings, UINT return check_order_activated(log, settings, orderName, condition, extendedMessage); } +WINPR_PRAGMA_DIAG_PUSH +WINPR_PRAGMA_DIAG_IGNORED_FORMAT_NONLITERAL static const char* primary_order_string(UINT32 orderType) { const char* orders[] = { "[0x%02" PRIx8 "] DstBlt", @@ -509,6 +511,7 @@ static const char* altsec_order_string(BYTE orderType) (void)sprintf_s(buffer, ARRAYSIZE(buffer), fmt, orderType); return buffer; } +WINPR_PRAGMA_DIAG_POP static INLINE BOOL update_read_coord(wStream* s, INT32* coord, BOOL delta) { diff --git a/server/Sample/sfreerdp.c b/server/Sample/sfreerdp.c index f7851ed08..edf4cea0a 100644 --- a/server/Sample/sfreerdp.c +++ b/server/Sample/sfreerdp.c @@ -1322,6 +1322,8 @@ static const struct const char skey[6]; } options = { "--pcap=", "--fast", "--port=", "--local-only", "--cert=", "--key=" }; +WINPR_PRAGMA_DIAG_PUSH +WINPR_PRAGMA_DIAG_IGNORED_FORMAT_NONLITERAL WINPR_ATTR_FORMAT_ARG(2, 0) static void print_entry(FILE* fp, WINPR_FORMAT_ARG const char* fmt, const char* what, size_t size) { @@ -1329,6 +1331,7 @@ static void print_entry(FILE* fp, WINPR_FORMAT_ARG const char* fmt, const char* strncpy(buffer, what, MIN(size, sizeof(buffer) - 1)); (void)fprintf(fp, fmt, buffer); } +WINPR_PRAGMA_DIAG_POP static WINPR_NORETURN(void usage(const char* app, const char* invalid)) { diff --git a/winpr/include/winpr/platform.h b/winpr/include/winpr/platform.h index 889c107bb..4fc3f8d95 100644 --- a/winpr/include/winpr/platform.h +++ b/winpr/include/winpr/platform.h @@ -41,6 +41,8 @@ _Pragma("clang diagnostic ignored \"-Wunused-const-variable\"") #define WINPR_PRAGMA_DIAG_IGNORED_FORMAT_SECURITY \ _Pragma("clang diagnostic ignored \"-Wformat-security\"") +#define WINPR_PRAGMA_DIAG_IGNORED_FORMAT_NONLITERAL \ + _Pragma("clang diagnostic ignored \"-Wformat-nonliteral\"") #define WINPR_PRAGMA_DIAG_IGNORED_MISMATCHED_DEALLOC /* not supported \ _Pragma("clang diagnostic ignored \"-Wmismatched-dealloc\"") */ #define WINPR_PRAGMA_DIAG_POP _Pragma("clang diagnostic pop") @@ -65,6 +67,8 @@ _Pragma("GCC diagnostic ignored \"-Wunused-const-variable\"") #define WINPR_PRAGMA_DIAG_IGNORED_FORMAT_SECURITY \ _Pragma("GCC diagnostic ignored \"-Wformat-security\"") +#define WINPR_PRAGMA_DIAG_IGNORED_FORMAT_NONLITERAL \ + _Pragma("GCC diagnostic ignored \"-Wformat-nonliteral\"") #if __GNUC__ >= 11 #define WINPR_PRAGMA_DIAG_IGNORED_MISMATCHED_DEALLOC \ _Pragma("GCC diagnostic ignored \"-Wmismatched-dealloc\"") @@ -84,6 +88,7 @@ #define WINPR_PRAGMA_DIAG_IGNORED_ATOMIC_SEQ_CST #define WINPR_PRAGMA_DIAG_IGNORED_UNUSED_CONST_VAR #define WINPR_PRAGMA_DIAG_IGNORED_FORMAT_SECURITY +#define WINPR_PRAGMA_DIAG_IGNORED_FORMAT_NONLITERAL #define WINPR_PRAGMA_DIAG_IGNORED_MISMATCHED_DEALLOC #define WINPR_PRAGMA_DIAG_POP #define WINPR_PRAGMA_UNROLL_LOOP diff --git a/winpr/libwinpr/utils/wlog/Layout.c b/winpr/libwinpr/utils/wlog/Layout.c index a34c7e4dd..86d942371 100644 --- a/winpr/libwinpr/utils/wlog/Layout.c +++ b/winpr/libwinpr/utils/wlog/Layout.c @@ -194,7 +194,10 @@ static BOOL replace_format_string(const char* FormatString, struct format_option if (replace && (replacelen > 0)) { + WINPR_PRAGMA_DIAG_PUSH + WINPR_PRAGMA_DIAG_IGNORED_FORMAT_NONLITERAL const int rc = _snprintf(&format[index], formatlen - index, replace, arg); + WINPR_PRAGMA_DIAG_POP if (rc < 0) return FALSE; if (!check_and_log_format_size(format, formatlen, index, rc)) diff --git a/winpr/libwinpr/utils/wlog/wlog.c b/winpr/libwinpr/utils/wlog/wlog.c index 492a79c36..d28cb521b 100644 --- a/winpr/libwinpr/utils/wlog/wlog.c +++ b/winpr/libwinpr/utils/wlog/wlog.c @@ -373,9 +373,12 @@ BOOL WLog_PrintMessageVA(wLog* log, DWORD type, DWORD level, size_t line, const { char formattedLogMessage[WLOG_MAX_STRING_SIZE] = { 0 }; + WINPR_PRAGMA_DIAG_PUSH + WINPR_PRAGMA_DIAG_IGNORED_FORMAT_NONLITERAL if (vsnprintf(formattedLogMessage, WLOG_MAX_STRING_SIZE - 1, message.FormatString, args) < 0) return FALSE; + WINPR_PRAGMA_DIAG_POP message.TextString = formattedLogMessage; status = WLog_Write(log, &message);