diff options
author | Ingo Schwarze <schwarze@openbsd.org> | 2011-12-20 21:41:11 +0000 |
---|---|---|
committer | Ingo Schwarze <schwarze@openbsd.org> | 2011-12-20 21:41:11 +0000 |
commit | 870872aa8fa9489f2f3b7be0026776ee2a54dad0 (patch) | |
tree | 088e810a0353ba103aa705d308e8832daf968923 | |
parent | 8b085aba08a98619780dc5406fca3cf10bb7cdb6 (diff) | |
download | mandoc-870872aa8fa9489f2f3b7be0026776ee2a54dad0.tar.gz |
Do not cast void pointers to pointers requiring alignment.
This makes mandocdb(8)/apropos(1) work on strict alignment architectures.
Basic way to fix this confirmed by deraadt@ and kettenis@, thanks.
ok kristaps@
This now works on both sparc64 and i386, but note that the binary
database format is still machine-dependent.
-rw-r--r-- | apropos_db.c | 11 | ||||
-rw-r--r-- | mandocdb.c | 16 |
2 files changed, 18 insertions, 9 deletions
diff --git a/apropos_db.c b/apropos_db.c index f50e91f2..79350f45 100644 --- a/apropos_db.c +++ b/apropos_db.c @@ -171,7 +171,7 @@ btree_read(const DBT *k, const DBT *v, const struct mchars *mc, struct db_val *dbv, char **buf) { - const struct db_val *vp; + struct db_val raw_dbv; /* Are our sizes sane? */ if (k->size < 2 || sizeof(struct db_val) != v->size) @@ -181,10 +181,10 @@ btree_read(const DBT *k, const DBT *v, if ('\0' != ((const char *)k->data)[(int)k->size - 1]) return(0); - vp = v->data; norm_string((const char *)k->data, mc, buf); - dbv->rec = betoh32(vp->rec); - dbv->mask = betoh64(vp->mask); + memcpy(&raw_dbv, v->data, v->size); + dbv->rec = betoh32(raw_dbv.rec); + dbv->mask = betoh64(raw_dbv.mask); return(1); } @@ -380,7 +380,8 @@ index_read(const DBT *key, const DBT *val, int index, return(0); cp = val->data; - rec->res.rec = *(recno_t *)key->data; + assert(sizeof(recno_t) == key->size); + memcpy(&rec->res.rec, key->data, key->size); rec->res.volume = index; if ('d' == (type = *cp++)) @@ -525,6 +525,7 @@ index_merge(const struct of *of, struct mparse *mp, struct mdoc *mdoc; struct man *man; const char *fn, *msec, *mtitle, *arch; + uint64_t mask; size_t sv; unsigned seq; struct db_val vbuf; @@ -655,7 +656,9 @@ index_merge(const struct of *of, struct mparse *mp, seq = R_FIRST; while (0 == (ch = (*hash->seq)(hash, &key, &val, seq))) { seq = R_NEXT; - vbuf.mask = htobe64(*(uint64_t *)val.data); + assert(sizeof(uint64_t) == val.size); + memcpy(&mask, val.data, val.size); + vbuf.mask = htobe64(mask); val.size = sizeof(struct db_val); val.data = &vbuf; dbt_put(db, dbf, &key, &val); @@ -708,7 +711,8 @@ index_prune(const struct of *ofile, DB *db, const char *dbf, seq = R_FIRST; while (0 == (ch = (*idx->seq)(idx, &key, &val, seq))) { seq = R_NEXT; - *maxrec = *(recno_t *)key.data; + assert(sizeof(recno_t) == key.size); + memcpy(maxrec, key.data, key.size); /* Deleted records are zero-sized. Skip them. */ @@ -1068,6 +1072,7 @@ pmdoc_Sh(MDOC_ARGS) static void hash_put(DB *db, const struct buf *buf, uint64_t mask) { + uint64_t oldmask; DBT key, val; int rc; @@ -1080,8 +1085,11 @@ hash_put(DB *db, const struct buf *buf, uint64_t mask) if ((rc = (*db->get)(db, &key, &val, 0)) < 0) { perror("hash"); exit((int)MANDOCLEVEL_SYSERR); - } else if (0 == rc) - mask |= *(uint64_t *)val.data; + } else if (0 == rc) { + assert(sizeof(uint64_t) == val.size); + memcpy(&oldmask, val.data, val.size); + mask |= oldmask; + } val.data = &mask; val.size = sizeof(uint64_t); |