From: Andrew Deason Date: Wed, 15 Sep 2010 16:19:33 +0000 (-0400) Subject: libafs: Fix pioctl get/putInt alignment issues X-Git-Tag: openafs-devel-1_5_78~141 X-Git-Url: https://git.michaelhowe.org/gitweb/?a=commitdiff_plain;h=1ac380b0d39fc0a4657ff134b0ef2d9bb63af3f1;p=packages%2Fo%2Fopenafs.git libafs: Fix pioctl get/putInt alignment issues We don't know if the buffer for pioctl data is aligned to anything, so we can't just dereference the given pointer as an int or anything else. So, just memcpy the data in for ints and such; conveniently, afs_pd_getBytes and afs_pd_putBytes can do this for us, so just use that. Change-Id: Id1abdae55308db6fe1e13f541a5d776daa6af934 Reviewed-on: http://gerrit.openafs.org/2763 Tested-by: Andrew Deason Tested-by: BuildBot Reviewed-by: Derrick Brashear (cherry picked from commit 8fd83543b60aefb4b7c5a0116d1538a89f58bbb3) Reviewed-on: http://gerrit.openafs.org/2801 Tested-by: Derrick Brashear --- diff --git a/src/afs/afs_pioctl.c b/src/afs/afs_pioctl.c index 9546d8198..c7576b9bd 100644 --- a/src/afs/afs_pioctl.c +++ b/src/afs/afs_pioctl.c @@ -106,31 +106,26 @@ afs_pd_skip(struct afs_pdata *apd, size_t skip) } static_inline int -afs_pd_getInt(struct afs_pdata *apd, afs_int32 *val) +afs_pd_getBytes(struct afs_pdata *apd, void *dest, size_t bytes) { - if (apd == NULL || apd->remaining < sizeof(afs_int32)) + if (apd == NULL || apd->remaining < bytes) return EINVAL; - apd->remaining -= sizeof(afs_int32); - *val = *(afs_int32 *)apd->ptr; - apd->ptr += sizeof(afs_int32); + apd->remaining -= bytes; + memcpy(dest, apd->ptr, bytes); + apd->ptr += bytes; return 0; } static_inline int -afs_pd_getUint(struct afs_pdata *apd, afs_uint32 *val) +afs_pd_getInt(struct afs_pdata *apd, afs_int32 *val) { - return afs_pd_getInt(apd, (afs_int32 *)val); + return afs_pd_getBytes(apd, val, sizeof(*val)); } static_inline int -afs_pd_getBytes(struct afs_pdata *apd, void *dest, size_t bytes) +afs_pd_getUint(struct afs_pdata *apd, afs_uint32 *val) { - if (apd == NULL || apd->remaining < bytes) - return EINVAL; - apd->remaining -= bytes; - memcpy(dest, apd->ptr, bytes); - apd->ptr += bytes; - return 0; + return afs_pd_getBytes(apd, val, sizeof(*val)); } static_inline void * @@ -179,18 +174,6 @@ afs_pd_getStringPtr(struct afs_pdata *apd, char **str) return 0; } -static_inline int -afs_pd_putInt(struct afs_pdata *apd, afs_int32 val) -{ - if (apd == NULL || apd->remaining < sizeof(afs_int32)) - return E2BIG; - *(afs_int32 *)apd->ptr = val; - apd->ptr += sizeof(afs_int32); - apd->remaining -= sizeof(afs_int32); - - return 0; -} - static_inline int afs_pd_putBytes(struct afs_pdata *apd, const void *bytes, size_t len) { @@ -202,6 +185,12 @@ afs_pd_putBytes(struct afs_pdata *apd, const void *bytes, size_t len) return 0; } +static_inline int +afs_pd_putInt(struct afs_pdata *apd, afs_int32 val) +{ + return afs_pd_putBytes(apd, &val, sizeof(val)); +} + static_inline int afs_pd_putString(struct afs_pdata *apd, char *str) {