From e956a0e155ad833daceebbd8941a4873f010d6e6 Mon Sep 17 00:00:00 2001 From: akallabeth Date: Wed, 29 Jun 2022 08:58:43 +0200 Subject: [PATCH] Added rail_get_order_type_string_full for better debug logs --- channels/rail/client/rail_orders.c | 12 ++++++++---- channels/rail/rail_common.c | 11 ++++++++--- channels/rail/rail_common.h | 1 + channels/rail/server/rail_main.c | 10 ++++++---- 4 files changed, 23 insertions(+), 11 deletions(-) diff --git a/channels/rail/client/rail_orders.c b/channels/rail/client/rail_orders.c index f2eb95a09..7950d188d 100644 --- a/channels/rail/client/rail_orders.c +++ b/channels/rail/client/rail_orders.c @@ -37,6 +37,7 @@ */ UINT rail_send_pdu(railPlugin* rail, wStream* s, UINT16 orderType) { + char buffer[128] = { 0 }; UINT16 orderLength; if (!rail || !s) @@ -47,7 +48,7 @@ UINT rail_send_pdu(railPlugin* rail, wStream* s, UINT16 orderType) rail_write_pdu_header(s, orderType, orderLength); Stream_SetPosition(s, orderLength); WLog_Print(rail->log, WLOG_DEBUG, "Sending %s PDU, length: %" PRIu16 "", - rail_get_order_type_string(orderType), orderLength); + rail_get_order_type_string_full(orderType, buffer, sizeof(buffer)), orderLength); return rail_send_channel_data(rail, s); } @@ -876,6 +877,7 @@ static UINT rail_recv_get_application_id_extended_response_order(railPlugin* rai */ UINT rail_order_recv(LPVOID userdata, wStream* s) { + char buffer[128] = { 0 }; railPlugin* rail = userdata; UINT16 orderType; UINT16 orderLength; @@ -891,7 +893,7 @@ UINT rail_order_recv(LPVOID userdata, wStream* s) } WLog_Print(rail->log, WLOG_DEBUG, "Received %s PDU, length:%" PRIu16 "", - rail_get_order_type_string(orderType), orderLength); + rail_get_order_type_string_full(orderType, buffer, sizeof(buffer)), orderLength); switch (orderType) { @@ -948,14 +950,16 @@ UINT rail_order_recv(LPVOID userdata, wStream* s) break; default: - WLog_ERR(TAG, "Unknown RAIL PDU order 0x%08" PRIx32 " received.", orderType); + WLog_ERR(TAG, "Unknown RAIL PDU %s received.", + rail_get_order_type_string_full(orderType, buffer, sizeof(buffer))); return ERROR_INVALID_DATA; } if (error != CHANNEL_RC_OK) { + char buffer[128] = { 0 }; WLog_Print(rail->log, WLOG_ERROR, "Failed to process rail %s PDU, length:%" PRIu16 "", - rail_get_order_type_string(orderType), orderLength); + rail_get_order_type_string_full(orderType, buffer, sizeof(buffer)), orderLength); } Stream_Free(s, TRUE); diff --git a/channels/rail/rail_common.c b/channels/rail/rail_common.c index bfacdd2d4..d24fd41be 100644 --- a/channels/rail/rail_common.c +++ b/channels/rail/rail_common.c @@ -29,7 +29,6 @@ const char* rail_get_order_type_string(UINT16 orderType) { - static char buffer[64] = { 0 }; switch (orderType) { case TS_RAIL_ORDER_EXEC: @@ -81,11 +80,17 @@ const char* rail_get_order_type_string(UINT16 orderType) case TS_RAIL_ORDER_EXEC_RESULT: return "TS_RAIL_ORDER_EXEC_RESULT"; default: - _snprintf(buffer, sizeof(buffer), "UNKNOWN [0x%08" PRIx32 "]", orderType); - return buffer; + return "TS_RAIL_ORDER_UNKNOWN"; } } +const char* rail_get_order_type_string_full(UINT16 orderType, char* buffer, size_t length) +{ + _snprintf(buffer, length, "%s[0x%04" PRIx16 "]", rail_get_order_type_string(orderType), + orderType); + return buffer; +} + /** * Function description * diff --git a/channels/rail/rail_common.h b/channels/rail/rail_common.h index e13412df9..34b6fa05d 100644 --- a/channels/rail/rail_common.h +++ b/channels/rail/rail_common.h @@ -71,5 +71,6 @@ UINT rail_write_sysparam_order(wStream* s, const RAIL_SYSPARAM_ORDER* sysparam, BOOL extendedSpiSupported); BOOL rail_is_extended_spi_supported(UINT32 channelsFlags); const char* rail_get_order_type_string(UINT16 orderType); +const char* rail_get_order_type_string_full(UINT16 orderType, char* buffer, size_t length); #endif /* FREERDP_CHANNEL_RAIL_COMMON_H */ diff --git a/channels/rail/server/rail_main.c b/channels/rail/server/rail_main.c index 65e395486..fe0384356 100644 --- a/channels/rail/server/rail_main.c +++ b/channels/rail/server/rail_main.c @@ -62,6 +62,7 @@ static UINT rail_send(RailServerContext* context, wStream* s, ULONG length) */ static UINT rail_server_send_pdu(RailServerContext* context, wStream* s, UINT16 orderType) { + char buffer[128] = { 0 }; UINT16 orderLength; if (!context || !s) @@ -71,8 +72,8 @@ static UINT rail_server_send_pdu(RailServerContext* context, wStream* s, UINT16 Stream_SetPosition(s, 0); rail_write_pdu_header(s, orderType, orderLength); Stream_SetPosition(s, orderLength); - WLog_DBG(TAG, "Sending %s PDU, length: %" PRIu16 "", rail_get_order_type_string(orderType), - orderLength); + WLog_DBG(TAG, "Sending %s PDU, length: %" PRIu16 "", + rail_get_order_type_string_full(orderType, buffer, sizeof(buffer)), orderLength); return rail_send(context, s, orderLength); } @@ -1535,6 +1536,7 @@ void rail_server_set_handshake_ex_flags(RailServerContext* context, DWORD flags) UINT rail_server_handle_messages(RailServerContext* context) { + char buffer[128] = { 0 }; UINT status = CHANNEL_RC_OK; DWORD bytesReturned; UINT16 orderType; @@ -1584,8 +1586,8 @@ UINT rail_server_handle_messages(RailServerContext* context) return ERROR_INTERNAL_ERROR; } - WLog_DBG(TAG, "Received %s PDU, length:%" PRIu16 "", rail_get_order_type_string(orderType), - orderLength); + WLog_DBG(TAG, "Received %s PDU, length:%" PRIu16 "", + rail_get_order_type_string_full(orderType, buffer, sizeof(buffer)), orderLength); switch (orderType) {