From: Andrew Deason Date: Wed, 15 Sep 2010 16:19:33 +0000 (-0400) Subject: libafs: Fix pioctl get/putInt alignment issues X-Git-Tag: upstream/1.8.0_pre1^2~4818 X-Git-Url: https://git.michaelhowe.org/gitweb/?a=commitdiff_plain;h=8fd83543b60aefb4b7c5a0116d1538a89f58bbb3;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 --- diff --git a/src/afs/afs_pioctl.c b/src/afs/afs_pioctl.c index 6b1a57c7f..f89998b96 100644 --- a/src/afs/afs_pioctl.c +++ b/src/afs/afs_pioctl.c @@ -107,31 +107,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 * @@ -197,18 +192,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) { @@ -220,6 +203,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) {