aboutsummaryrefslogtreecommitdiffstats
path: root/unmarshal.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2022-07-07 14:13:27 +0200
committerMattias Andrée <maandree@kth.se>2022-07-07 14:13:27 +0200
commit8cedc519bf235a52e2c85cd06bb0ec7d392bf0ca (patch)
tree539b994009afb20a537148d4236b6d443e06fba0 /unmarshal.c
parentRemove documentation from .c files that already exist in .h files (diff)
downloadlibsha1-8cedc519bf235a52e2c85cd06bb0ec7d392bf0ca.tar.gz
libsha1-8cedc519bf235a52e2c85cd06bb0ec7d392bf0ca.tar.bz2
libsha1-8cedc519bf235a52e2c85cd06bb0ec7d392bf0ca.tar.xz
Don't marshal w
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'unmarshal.c')
-rw-r--r--unmarshal.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/unmarshal.c b/unmarshal.c
index 25771b9..c6668ac 100644
--- a/unmarshal.c
+++ b/unmarshal.c
@@ -7,13 +7,15 @@ libsha1_unmarshal(struct libsha1_state *restrict state, const void *restrict buf
{
const char *restrict buf = buf_;
size_t off = 0;
+ int version;
if (bufsize < sizeof(int) + sizeof(enum libsha1_algorithm) + sizeof(size_t)) {
errno = EINVAL;
return 0;
}
- if (*(const int *)buf) { /* version */
+ version = *(const int *)buf;
+ if (version < 0 || version > 1) { /* version */
errno = EINVAL;
return 0;
}
@@ -28,8 +30,9 @@ libsha1_unmarshal(struct libsha1_state *restrict state, const void *restrict buf
errno = EINVAL;
return 0;
}
- memcpy(state->w, &buf[off], sizeof(state->w));
- off += sizeof(state->w);
+ memset(state->w, 0, sizeof(state->w));
+ if (version == 0)
+ off += sizeof(state->w);
memcpy(state->h, &buf[off], sizeof(state->h));
off += sizeof(state->h);