From 3c3a199f287faa7e3b714c6c7c39e5b35d61ef10 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sun, 10 Feb 2019 11:39:37 +0100 Subject: Marshal/Unmarshal: do no marshal unset bytes in the chunk MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- marshal.c | 4 ++-- unmarshal.c | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/marshal.c b/marshal.c index 75a8749..cae5b20 100644 --- a/marshal.c +++ b/marshal.c @@ -50,8 +50,8 @@ libsha2_marshal(const struct libsha2_state *restrict state, char *restrict buf) *(size_t *)&buf[off] = state->chunk_size; off += sizeof(size_t); if (buf) - memcpy(&buf[off], state->chunk, state->chunk_size); - off += state->chunk_size; + memcpy(&buf[off], state->chunk, state->message_size % state->chunk_size); + off += state->message_size % state->chunk_size; return off; } diff --git a/unmarshal.c b/unmarshal.c index 315d556..6bbfaa0 100644 --- a/unmarshal.c +++ b/unmarshal.c @@ -74,12 +74,12 @@ libsha2_unmarshal(struct libsha2_state *restrict state, const char *restrict buf state->chunk_size = *(const size_t *)&buf[off]; off += sizeof(size_t); - if (bufsize - off < state->chunk_size) { + if (bufsize - off < state->message_size % state->chunk_size) { errno = EINVAL; return 0; } - memcpy(state->chunk, &buf[off], state->chunk_size); - off += state->chunk_size; + memcpy(state->chunk, &buf[off], state->message_size % state->chunk_size); + off += state->message_size % state->chunk_size; return off; } -- cgit v1.2.3-70-g09d2