diff options
author | 2015-11-18 17:59:56 +0000 | |
---|---|---|
committer | 2015-11-18 17:59:56 +0000 | |
commit | 025678fa0f847e0cd20a1ed000f03494c5e19cfb (patch) | |
tree | 7777d768a32a664e85ff2f29e0e8a45a93d70e2f /lib/libc/stdlib/icdb.c | |
parent | Now that the transition is over, have the installer set 'prohibit-password' (diff) | |
download | wireguard-openbsd-025678fa0f847e0cd20a1ed000f03494c5e19cfb.tar.xz wireguard-openbsd-025678fa0f847e0cd20a1ed000f03494c5e19cfb.zip |
add a version field to prevent mayhem if different data gets stored
Diffstat (limited to 'lib/libc/stdlib/icdb.c')
-rw-r--r-- | lib/libc/stdlib/icdb.c | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/lib/libc/stdlib/icdb.c b/lib/libc/stdlib/icdb.c index 077c59a1e47..35747c065fc 100644 --- a/lib/libc/stdlib/icdb.c +++ b/lib/libc/stdlib/icdb.c @@ -1,4 +1,4 @@ -/* $OpenBSD: icdb.c,v 1.1 2015/11/18 16:46:49 tedu Exp $ */ +/* $OpenBSD: icdb.c,v 1.2 2015/11/18 17:59:56 tedu Exp $ */ /* * Copyright (c) 2015 Ted Unangst <tedu@openbsd.org> * @@ -77,6 +77,7 @@ */ struct icdbinfo { uint32_t magic; /* magic */ + uint32_t version; /* user specified version */ uint32_t nentries; /* number of entries stored */ uint32_t entrysize; /* size of each entry */ uint32_t indexsize; /* number of entries in hash index */ @@ -112,7 +113,7 @@ roundup(uint32_t num) } struct icdb * -icdb_new(uint32_t nentries, uint32_t entrysize, +icdb_new(uint32_t version, uint32_t nentries, uint32_t entrysize, uint32_t nkeys, uint32_t *keysizes, uint32_t *keyoffsets) { struct icdb *db; @@ -133,6 +134,7 @@ icdb_new(uint32_t nentries, uint32_t entrysize, db->info = info; db->fd = -1; info->magic = magic; + info->version = version; if (nentries) if ((db->entries = reallocarray(NULL, nentries, entrysize))) db->allocated = nentries; @@ -146,7 +148,7 @@ icdb_new(uint32_t nentries, uint32_t entrysize, } struct icdb * -icdb_open(const char *name, int flags) +icdb_open(const char *name, int flags, uint32_t version) { struct icdb *db = NULL; struct icdbinfo *info; @@ -166,6 +168,8 @@ icdb_open(const char *name, int flags) info = (struct icdbinfo *)ptr; if (info->magic != magic) goto fail; + if (info->version != version) + goto fail; if (!(db = calloc(1, sizeof(*db)))) goto fail; |