80177b4
From be86f37814a3f80bb1e827be1e08e608d8f304f4 Mon Sep 17 00:00:00 2001
80177b4
From: Joey Degges <jdegges@gmail.com>
80177b4
Date: Tue, 21 Dec 2010 02:53:20 -0800
80177b4
Subject: [PATCH] _libssh2_ntohu64: fix conversion from network bytes to uint64
80177b4
80177b4
Cast individual bytes to uint64 to avoid overflow in arithmetic.
80177b4
80177b4
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
80177b4
---
80177b4
 src/misc.c |    6 ++++--
80177b4
 1 files changed, 4 insertions(+), 2 deletions(-)
80177b4
80177b4
diff --git a/src/misc.c b/src/misc.c
80177b4
index e6c5e99..a5e540c 100644
80177b4
--- a/src/misc.c
80177b4
+++ b/src/misc.c
80177b4
@@ -148,8 +148,10 @@ _libssh2_ntohu64(const unsigned char *buf)
80177b4
 {
80177b4
     unsigned long msl, lsl;
80177b4
 
80177b4
-    msl = (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3];
80177b4
-    lsl = (buf[4] << 24) | (buf[5] << 16) | (buf[6] << 8) | buf[7];
80177b4
+    msl = ((libssh2_uint64_t)buf[0] << 24) | ((libssh2_uint64_t)buf[1] << 16)
80177b4
+        | ((libssh2_uint64_t)buf[2] << 8) | (libssh2_uint64_t)buf[3];
80177b4
+    lsl = ((libssh2_uint64_t)buf[4] << 24) | ((libssh2_uint64_t)buf[5] << 16)
80177b4
+        | ((libssh2_uint64_t)buf[6] << 8) | (libssh2_uint64_t)buf[7];
80177b4
 
80177b4
     return ((libssh2_uint64_t)msl <<32) | lsl;
80177b4
 }
80177b4
-- 
80177b4
1.7.1
80177b4