diff options
author | Tom Yu <tlyu@mit.edu> | 2016-08-26 13:56:18 -0400 |
---|---|---|
committer | Tom Yu <tlyu@mit.edu> | 2016-09-02 14:49:39 -0400 |
commit | 2e1d229805ef1358ae8e975d7972ec717ed5c5e2 (patch) | |
tree | c606ae34b5ced8c6979e90025870d2c8500feb05 | |
parent | c0ecbfbac487fc532487f084332739edd91af76d (diff) | |
download | krb5-2e1d229805ef1358ae8e975d7972ec717ed5c5e2.zip krb5-2e1d229805ef1358ae8e975d7972ec717ed5c5e2.tar.gz krb5-2e1d229805ef1358ae8e975d7972ec717ed5c5e2.tar.bz2 |
Avoid unaligned access in btree byte swapping
Apply a patch from NetBSD to use temporary character buffers instead
of doing an unaligned read when swapping bytes.
(cherry picked from commit 0936b2578b64be2c53c8cfccd70cbe93519d42fa)
ticket: 8484
version_fixed: 1.14.4
-rw-r--r-- | src/plugins/kdb/db2/libdb2/include/db-int.h | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/src/plugins/kdb/db2/libdb2/include/db-int.h b/src/plugins/kdb/db2/libdb2/include/db-int.h index 0dcbf40..7e981d4 100644 --- a/src/plugins/kdb/db2/libdb2/include/db-int.h +++ b/src/plugins/kdb/db2/libdb2/include/db-int.h @@ -160,11 +160,15 @@ typedef u_int32_t recno_t; ((char *)&a)[3] = ((char *)&_tmp)[0]; \ } #define P_32_SWAP(a) { \ - u_int32_t _tmp = *(u_int32_t *)a; \ - ((char *)a)[0] = ((char *)&_tmp)[3]; \ - ((char *)a)[1] = ((char *)&_tmp)[2]; \ - ((char *)a)[2] = ((char *)&_tmp)[1]; \ - ((char *)a)[3] = ((char *)&_tmp)[0]; \ + char _tmp[4]; \ + _tmp[0] = ((char *)a)[0]; \ + _tmp[1] = ((char *)a)[1]; \ + _tmp[2] = ((char *)a)[2]; \ + _tmp[3] = ((char *)a)[3]; \ + ((char *)a)[0] = _tmp[3]; \ + ((char *)a)[1] = _tmp[2]; \ + ((char *)a)[2] = _tmp[1]; \ + ((char *)a)[3] = _tmp[0]; \ } #define P_32_COPY(a, b) { \ ((char *)&(b))[0] = ((char *)&(a))[3]; \ @@ -185,9 +189,11 @@ typedef u_int32_t recno_t; ((char *)&a)[1] = ((char *)&_tmp)[0]; \ } #define P_16_SWAP(a) { \ - u_int16_t _tmp = *(u_int16_t *)a; \ - ((char *)a)[0] = ((char *)&_tmp)[1]; \ - ((char *)a)[1] = ((char *)&_tmp)[0]; \ + char _tmp[2]; \ + _tmp[0] = ((char *)a)[0]; \ + _tmp[1] = ((char *)a)[1]; \ + ((char *)a)[0] = _tmp[1]; \ + ((char *)a)[1] = _tmp[0]; \ } #define P_16_COPY(a, b) { \ ((char *)&(b))[0] = ((char *)&(a))[1]; \ |