]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
daemon TTY: use network byte order in binary output
authorVladimír Čunát <vladimir.cunat@nic.cz>
Tue, 31 Jan 2017 15:50:56 +0000 (16:50 +0100)
committerŠtěpán Balážik <stepan.balazik@nic.cz>
Fri, 3 Feb 2017 18:29:15 +0000 (19:29 +0100)
That's to allow tunnelling the TTY to a different endian.

daemon/kresc.c
daemon/main.c

index 5aebeae60c1eebb6b8d8b47a2dc982bc11e589ee..201651ecc770f292f2aa9b52f08fca34baa58d12 100644 (file)
@@ -13,6 +13,7 @@
     You should have received a copy of the GNU General Public License
     along with this program.  If not, see <https://www.gnu.org/licenses/>.
  */
+#include <arpa/inet.h>
 #include <assert.h>
 #include <contrib/ccan/asprintf/asprintf.h>
 #include <editline/readline.h>
@@ -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;
index 404b2cedac40e4b82766ab2b3714b050b7240160..8e66348f661b0dbefb19877d4aa63b0f3985eaa8 100644 (file)
@@ -14,6 +14,7 @@
     along with this program.  If not, see <https://www.gnu.org/licenses/>.
  */
 
+#include <arpa/inet.h>
 #include <stdlib.h>
 #include <string.h>
 #include <getopt.h>
@@ -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;
                }