diff --git a/src/event.c b/src/event.c index a12f23b..7a9bada 100644 --- a/src/event.c +++ b/src/event.c @@ -166,7 +166,9 @@ int hyper_event_read(struct hyper_event *he, int efd) } fprintf(stdout, "get length %" PRIu32"\n", len); - if (len > buf->size) { + // test it with '>=' to leave at least one byte in handle(), + // so that handle() can convert the data to c-string inplace. + if (len >= buf->size) { fprintf(stderr, "get length %" PRIu32", too long\n", len); return -1; } diff --git a/src/init.c b/src/init.c index 9264c7e..2b87f4e 100644 --- a/src/init.c +++ b/src/init.c @@ -1062,6 +1062,8 @@ static int hyper_channel_handle(struct hyper_event *de, uint32_t len) uint8_t *data = NULL; int i, ret = 0; + // append a null byte to it. hyper_event_read() left this room for us. + buf->data[buf->get] = 0; for (i = 0; i < buf->get; i++) fprintf(stdout, "%0x ", buf->data[i]);