[libvirt] [PATCH] Fix 32-bit int truncation in QED header check

* src/util/memory.c: Avoid 32-bit truncation extracting a 64bit int --- src/util/storage_file.c | 16 ++++++++-------- 1 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/util/storage_file.c b/src/util/storage_file.c index aa117e7..37d3ecf 100644 --- a/src/util/storage_file.c +++ b/src/util/storage_file.c @@ -437,14 +437,14 @@ qedGetHeaderUL(const unsigned char *loc) static unsigned long long qedGetHeaderULL(const unsigned char *loc) { - return ( ((unsigned long)loc[7] << 56) - | ((unsigned long)loc[6] << 48) - | ((unsigned long)loc[5] << 40) - | ((unsigned long)loc[4] << 32) - | ((unsigned long)loc[3] << 24) - | ((unsigned long)loc[2] << 16) - | ((unsigned long)loc[1] << 8) - | ((unsigned long)loc[0] << 0)); + return ( ((unsigned long long)loc[7] << 56) + | ((unsigned long long)loc[6] << 48) + | ((unsigned long long)loc[5] << 40) + | ((unsigned long long)loc[4] << 32) + | ((unsigned long long)loc[3] << 24) + | ((unsigned long long)loc[2] << 16) + | ((unsigned long long)loc[1] << 8) + | ((unsigned long long)loc[0] << 0)); } static int -- 1.7.2.3

On 11/23/2010 06:34 AM, Daniel P. Berrange wrote:
* src/util/memory.c: Avoid 32-bit truncation extracting a 64bit int --- src/util/storage_file.c | 16 ++++++++-------- 1 files changed, 8 insertions(+), 8 deletions(-)
ACK, and apologies for not catching that. I'm still convinced that both little- and big-endian value parsing are common enough routines that ought to be shared by more than just QED, so I'll add that to my TODO queue of low-hanging patches to write. -- Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org
participants (2)
-
Daniel P. Berrange
-
Eric Blake