From: Vladimír Čunát Date: Tue, 31 Jan 2017 15:50:56 +0000 (+0100) Subject: daemon TTY: use network byte order in binary output X-Git-Tag: v1.3.0~23^2~86^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=48c8129fd03489148b788dfb32234d827aa2263a;p=thirdparty%2Fknot-resolver.git daemon TTY: use network byte order in binary output That's to allow tunnelling the TTY to a different endian. --- diff --git a/daemon/kresc.c b/daemon/kresc.c index 5aebeae60..201651ecc 100644 --- a/daemon/kresc.c +++ b/daemon/kresc.c @@ -13,6 +13,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ +#include #include #include #include @@ -309,6 +310,7 @@ static char *run_cmd(const char *cmd, size_t * out_len) uint32_t len; if (!fread(&len, sizeof(len), 1, g_tty)) return NULL; + len = ntohl(len); char *msg = malloc(1 + (size_t) len); if (!msg) return NULL; diff --git a/daemon/main.c b/daemon/main.c index 404b2ceda..8e66348f6 100644 --- a/daemon/main.c +++ b/daemon/main.c @@ -14,6 +14,7 @@ along with this program. If not, see . */ +#include #include #include #include @@ -63,6 +64,7 @@ static inline char *lua_strerror(int lua_err) { * * - This is just basic read-eval-print; libedit is supported through krsec; * - stream->data represents a bool determining binary output mode (used by kresc); + * - binary output: uint32_t length in network order, followed by that many bytes; */ static void tty_process_input(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf) { @@ -125,9 +127,9 @@ static void tty_process_input(uv_stream_t *stream, ssize_t nread, const uv_buf_t size_t len_s = strlen(message); if (len_s > UINT32_MAX) goto finish; - uint32_t len = len_s; - fwrite(&len, sizeof(len), 1, out); - fwrite(message, len, 1, out); + uint32_t len_n = htonl(len_s); + fwrite(&len_n, sizeof(len_n), 1, out); + fwrite(message, len_s, 1, out); goto finish; }