aboutsummaryrefslogtreecommitdiffstats
path: root/unmarshal.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2019-02-10 11:28:30 +0100
committerMattias Andrée <maandree@kth.se>2019-02-10 11:28:30 +0100
commitd84edd9500e6e22ba49c76dc93a7c0731755d008 (patch)
tree5238a0362e0f70ea44fa40906c86102d5a50a4eb /unmarshal.c
parentFix warnings (diff)
downloadlibsha2-d84edd9500e6e22ba49c76dc93a7c0731755d008.tar.gz
libsha2-d84edd9500e6e22ba49c76dc93a7c0731755d008.tar.bz2
libsha2-d84edd9500e6e22ba49c76dc93a7c0731755d008.tar.xz
Fix libsha2_digest + minor improvements
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
-rw-r--r--unmarshal.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/unmarshal.c b/unmarshal.c
index 13a97ff..315d556 100644
--- a/unmarshal.c
+++ b/unmarshal.c
@@ -67,14 +67,19 @@ libsha2_unmarshal(struct libsha2_state *restrict state, const char *restrict buf
return 0;
}
- if (bufsize - off < sizeof(state->chunk) + sizeof(size_t)) {
+ if (bufsize - off < sizeof(size_t)) {
errno = EINVAL;
return 0;
}
- memcpy(state->chunk, &buf[off], sizeof(state->chunk));
- off += sizeof(state->chunk);
state->chunk_size = *(const size_t *)&buf[off];
off += sizeof(size_t);
+ if (bufsize - off < state->chunk_size) {
+ errno = EINVAL;
+ return 0;
+ }
+ memcpy(state->chunk, &buf[off], state->chunk_size);
+ off += state->chunk_size;
+
return off;
}