From fd691deb1786caff8add1def457749b91a72394e Mon Sep 17 00:00:00 2001 From: Joey Degges Date: Tue, 21 Dec 2010 02:53:20 -0800 Subject: [PATCH] _libssh2_ntohu64: fix conversion from network bytes to uint64 Cast individual bytes to uint64 to avoid overflow in arithmetic. --- src/misc.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/misc.c b/src/misc.c index 489605cd..592a874e 100644 --- a/src/misc.c +++ b/src/misc.c @@ -156,8 +156,10 @@ _libssh2_ntohu64(const unsigned char *buf) { unsigned long msl, lsl; - msl = (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3]; - lsl = (buf[4] << 24) | (buf[5] << 16) | (buf[6] << 8) | buf[7]; + msl = ((libssh2_uint64_t)buf[0] << 24) | ((libssh2_uint64_t)buf[1] << 16) + | ((libssh2_uint64_t)buf[2] << 8) | (libssh2_uint64_t)buf[3]; + lsl = ((libssh2_uint64_t)buf[4] << 24) | ((libssh2_uint64_t)buf[5] << 16) + | ((libssh2_uint64_t)buf[6] << 8) | (libssh2_uint64_t)buf[7]; return ((libssh2_uint64_t)msl <<32) | lsl; }