From d32953c405404442cbf6b29dd83dfe8dd1a7713a Mon Sep 17 00:00:00 2001 From: matt335672 <30179339+matt335672@users.noreply.github.com> Date: Thu, 2 Sep 2021 17:08:53 +0100 Subject: [PATCH] Parse DEVICE_ANNOUNCE header correctly --- common/parse.h | 2 ++ sesman/chansrv/devredir.c | 55 +++++++++++++++++++++------------------ 2 files changed, 32 insertions(+), 25 deletions(-) diff --git a/common/parse.h b/common/parse.h index 500d57d7..b27bb0c9 100644 --- a/common/parse.h +++ b/common/parse.h @@ -498,6 +498,8 @@ parser_stream_overflow_check(const struct stream *s, int n, int is_out, *****************************************************************************/ #define xstream_free(_s) free_stream(_s) +#define xstream_skip_u8(_s, _n) in_uint8s(_s, _n) + #define xstream_rd_u8(_s, _var) in_uint8(_s, _var) #define xstream_rd_u16_le(_s, _var) in_uint16_le(_s, _var) #define xstream_rd_u32_le(_s, _var) in_uint32_le(_s, _var) diff --git a/sesman/chansrv/devredir.c b/sesman/chansrv/devredir.c index d5f7313a..b50c6049 100644 --- a/sesman/chansrv/devredir.c +++ b/sesman/chansrv/devredir.c @@ -814,18 +814,24 @@ devredir_proc_client_devlist_announce_req(struct stream *s) /* Assume this device isn't supported by us */ response_status = STATUS_NOT_SUPPORTED; + /* Read the device data length from the stream */ + xstream_rd_u32_le(s, device_data_len); + switch (device_type) { case RDPDR_DTYP_FILESYSTEM: /* get device data len */ - xstream_rd_u32_le(s, device_data_len); if (device_data_len) { xstream_rd_string(g_full_name_for_filesystem, s, device_data_len); } - LOG_DEVEL(LOG_LEVEL_DEBUG, "device_type=FILE_SYSTEM device_id=0x%x dosname=%s " + LOG(LOG_LEVEL_INFO, "detected remote drive %s", + preferred_dos_name); + + LOG_DEVEL(LOG_LEVEL_DEBUG, + "device_type=FILE_SYSTEM device_id=0x%x dosname=%s " "device_data_len=%d full_name=%s", g_device_id, preferred_dos_name, device_data_len, g_full_name_for_filesystem); @@ -838,9 +844,13 @@ devredir_proc_client_devlist_announce_req(struct stream *s) break; case RDPDR_DTYP_SMARTCARD: - /* for smart cards, device data len always 0 */ + xstream_skip_u8(s, device_data_len); - LOG_DEVEL(LOG_LEVEL_DEBUG, "device_type=SMARTCARD device_id=0x%x dosname=%s", + LOG(LOG_LEVEL_INFO, "Detected remote smartcard '%s'", + preferred_dos_name); + + LOG_DEVEL(LOG_LEVEL_DEBUG, + "device_type=SMARTCARD device_id=0x%x dosname=%s", g_device_id, preferred_dos_name); response_status = STATUS_SUCCESS; @@ -848,29 +858,24 @@ devredir_proc_client_devlist_announce_req(struct stream *s) scard_device_announce(g_device_id); break; - case RDPDR_DTYP_SERIAL: - LOG_DEVEL(LOG_LEVEL_DEBUG, - "device_type=SERIAL device_id=0x%x dosname=%s", - g_device_id, preferred_dos_name); - break; - - case RDPDR_DTYP_PARALLEL: - LOG_DEVEL(LOG_LEVEL_DEBUG, - "device_type=PARALLEL device_id=0x%x dosname=%s", - g_device_id, preferred_dos_name); - break; - - case RDPDR_DTYP_PRINT: - LOG_DEVEL(LOG_LEVEL_DEBUG, - "device_type=PRINT device_id=0x%x dosname=%s", - g_device_id, preferred_dos_name); - break; - default: + { + /* All other devices are unsupported */ + const char *description = + (device_type == RDPDR_DTYP_SERIAL) ? "serial port" : + (device_type == RDPDR_DTYP_PARALLEL) ? "parallel port" : + (device_type == RDPDR_DTYP_PRINT) ? "printer" : + /* default */ "unknown device"; + + xstream_skip_u8(s, device_data_len); + LOG(LOG_LEVEL_INFO, "Remote %s '%s' is not supported" + " and will be ignored", + description, preferred_dos_name); LOG_DEVEL(LOG_LEVEL_DEBUG, - "device_type=UNKNOWN device_id=0x%x dosname=%s", - g_device_id, preferred_dos_name); - break; + "description=%s dosname=%s device_id=0x%x", + description, preferred_dos_name, g_device_id); + } + break; } /* Tell the client wheth or not we're supporting this one */