From 3ab2a6f791d3e14f0b30c0f98974ad80a83ab5f0 Mon Sep 17 00:00:00 2001 From: pimlie Date: Thu, 1 Dec 2016 12:49:12 +0100 Subject: [PATCH 1/8] Fix for buffer containing \0 characters --- util/telnet-client.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/util/telnet-client.c b/util/telnet-client.c index 66f893e..dc582cb 100644 --- a/util/telnet-client.c +++ b/util/telnet-client.c @@ -100,7 +100,9 @@ static void _event_handler(telnet_t *telnet, telnet_event_t *ev, switch (ev->type) { /* data received */ case TELNET_EV_DATA: - printf("%.*s", (int)ev->data.size, ev->data.buffer); + if (ev->data.size && fwrite(ev->data.buffer, 1, ev->data.size, stdout) != ev->data.size) { + fprintf(stderr, "ERROR: Could not write complete buffer to stdout"); + } fflush(stdout); break; /* data must be sent */ From cd0efb3f96e7736338ce601b10fbb0fb9d89a8f5 Mon Sep 17 00:00:00 2001 From: Yusuke Ichinohe Date: Tue, 8 Nov 2016 02:17:56 +0900 Subject: [PATCH 2/8] Fix compile with Visual C++ 2015 --- libtelnet.h | 5 +++++ util/telnet-chatd.c | 6 ++++++ util/telnet-proxy.c | 3 +++ 3 files changed, 14 insertions(+) diff --git a/libtelnet.h b/libtelnet.h index affcd9d..da6126b 100644 --- a/libtelnet.h +++ b/libtelnet.h @@ -59,6 +59,11 @@ extern "C" { # define TELNET_GNU_SENTINEL /*!< internal helper */ #endif +/* Disable environ macro in Visual C++ */ +#ifdef _MSC_VER +# undef environ +#endif + /*! Telnet state tracker object type. */ typedef struct telnet_t telnet_t; diff --git a/util/telnet-chatd.c b/util/telnet-chatd.c index 18ad83e..0149e4e 100644 --- a/util/telnet-chatd.c +++ b/util/telnet-chatd.c @@ -27,12 +27,18 @@ # include # include +#if !defined(_MSC_VER) || _MSC_VER < 1800 # define snprintf _snprintf +#endif + # define poll WSAPoll # define close closesocket # define strdup _strdup + +#if !defined(_MSC_VER) || _MSC_VER < 1600 // VC 9 and prior do not define this macro # define ECONNRESET WSAECONNRESET #endif +#endif #include #include diff --git a/util/telnet-proxy.c b/util/telnet-proxy.c index 0d1dc3e..72484a1 100644 --- a/util/telnet-proxy.c +++ b/util/telnet-proxy.c @@ -27,7 +27,10 @@ # include # include +#if !defined(_MSC_VER) || _MSC_VER < 1900 # define snprintf _snprintf +#endif + # define poll WSAPoll # define close closesocket From 7c188a326e28021fa42f04d7ba3aa11477422cc3 Mon Sep 17 00:00:00 2001 From: Yusuke Ichinohe Date: Tue, 8 Nov 2016 02:18:35 +0900 Subject: [PATCH 3/8] Fix to use gai_strerrorA --- msvc2010/telnet-proxy.vcxproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/msvc2010/telnet-proxy.vcxproj b/msvc2010/telnet-proxy.vcxproj index fb29294..ea6682d 100644 --- a/msvc2010/telnet-proxy.vcxproj +++ b/msvc2010/telnet-proxy.vcxproj @@ -18,12 +18,12 @@ Application - Unicode + MultiByte true Application - Unicode + MultiByte From 4d2951422cf2aacff0f1b6baf1a3bedd45225673 Mon Sep 17 00:00:00 2001 From: Yusuke Ichinohe Date: Sat, 3 Dec 2016 23:37:28 +0900 Subject: [PATCH 4/8] Revert "Fix to use gai_strerrorA" This reverts commit 3334b7eb186ef56dc37ed2bd371976745e9a9115. --- msvc2010/telnet-proxy.vcxproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/msvc2010/telnet-proxy.vcxproj b/msvc2010/telnet-proxy.vcxproj index ea6682d..fb29294 100644 --- a/msvc2010/telnet-proxy.vcxproj +++ b/msvc2010/telnet-proxy.vcxproj @@ -18,12 +18,12 @@ Application - MultiByte + Unicode true Application - MultiByte + Unicode From 61ea04b0f0a7c53b72afff15d32584c51139444b Mon Sep 17 00:00:00 2001 From: Yusuke Ichinohe Date: Sun, 4 Dec 2016 01:58:45 +0900 Subject: [PATCH 5/8] Always use gai_strerrorA in _WIN32 gai_strerror is used with %s of printf --- util/telnet-proxy.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/util/telnet-proxy.c b/util/telnet-proxy.c index 72484a1..951a3cf 100644 --- a/util/telnet-proxy.c +++ b/util/telnet-proxy.c @@ -33,6 +33,8 @@ # define poll WSAPoll # define close closesocket +# undef gai_strerror +# define gai_strerror gai_strerrorA #if !defined(_MSC_VER) || _MSC_VER < 1600 // VC 9 and prior do not define this macro # define ECONNRESET WSAECONNRESET From 9a2a3665320bca95a953a4096834f50916fc267d Mon Sep 17 00:00:00 2001 From: Yusuke Ichinohe Date: Sun, 4 Dec 2016 02:25:17 +0900 Subject: [PATCH 6/8] Always undef environ --- libtelnet.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/libtelnet.h b/libtelnet.h index da6126b..0103236 100644 --- a/libtelnet.h +++ b/libtelnet.h @@ -59,10 +59,8 @@ extern "C" { # define TELNET_GNU_SENTINEL /*!< internal helper */ #endif -/* Disable environ macro in Visual C++ */ -#ifdef _MSC_VER -# undef environ -#endif +/* Disable environ macro for Visual C++ 2015. */ +#undef environ /*! Telnet state tracker object type. */ typedef struct telnet_t telnet_t; From f2aee359aef93f005a478ef29d4a824dc5dc4011 Mon Sep 17 00:00:00 2001 From: Yusuke Ichinohe Date: Sun, 4 Dec 2016 02:32:39 +0900 Subject: [PATCH 7/8] Remove #if for ECONNRESET in _WIN32 --- util/telnet-chatd.c | 3 --- util/telnet-proxy.c | 3 --- 2 files changed, 6 deletions(-) diff --git a/util/telnet-chatd.c b/util/telnet-chatd.c index 0149e4e..4468bd4 100644 --- a/util/telnet-chatd.c +++ b/util/telnet-chatd.c @@ -34,11 +34,8 @@ # define poll WSAPoll # define close closesocket # define strdup _strdup - -#if !defined(_MSC_VER) || _MSC_VER < 1600 // VC 9 and prior do not define this macro # define ECONNRESET WSAECONNRESET #endif -#endif #include #include diff --git a/util/telnet-proxy.c b/util/telnet-proxy.c index 951a3cf..1896310 100644 --- a/util/telnet-proxy.c +++ b/util/telnet-proxy.c @@ -35,11 +35,8 @@ # define close closesocket # undef gai_strerror # define gai_strerror gai_strerrorA - -#if !defined(_MSC_VER) || _MSC_VER < 1600 // VC 9 and prior do not define this macro # define ECONNRESET WSAECONNRESET #endif -#endif #include #include From 66013f7ef67c055ba9d12f2d336d62242c01761f Mon Sep 17 00:00:00 2001 From: Yusuke Ichinohe Date: Sun, 4 Dec 2016 02:41:01 +0900 Subject: [PATCH 8/8] Fix condition of #define snprintf _snprintf Use _UCRT instead _MSC_VER --- util/telnet-chatd.c | 2 +- util/telnet-proxy.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/util/telnet-chatd.c b/util/telnet-chatd.c index 4468bd4..9d41150 100644 --- a/util/telnet-chatd.c +++ b/util/telnet-chatd.c @@ -27,7 +27,7 @@ # include # include -#if !defined(_MSC_VER) || _MSC_VER < 1800 +#ifndef _UCRT # define snprintf _snprintf #endif diff --git a/util/telnet-proxy.c b/util/telnet-proxy.c index 1896310..dad6ea7 100644 --- a/util/telnet-proxy.c +++ b/util/telnet-proxy.c @@ -27,7 +27,7 @@ # include # include -#if !defined(_MSC_VER) || _MSC_VER < 1900 +#ifndef _UCRT # define snprintf _snprintf #endif