From de483c51dccb7b276c1b0504127c529474334635 Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Sun, 15 Jan 2012 11:36:35 +0200 Subject: [PATCH 1/1] Fix byte swapping in auth library --- stglibs/ia.lib/ia.cpp | 54 +++++++++++++++++++++++-------------------- 1 file changed, 29 insertions(+), 25 deletions(-) diff --git a/stglibs/ia.lib/ia.cpp b/stglibs/ia.lib/ia.cpp index 148750d2..4f6468ba 100644 --- a/stglibs/ia.lib/ia.cpp +++ b/stglibs/ia.lib/ia.cpp @@ -720,13 +720,14 @@ int IA_CLIENT_PROT::Prepare_CONN_SYN_8(char * buffer) { connSyn8 = (CONN_SYN_8*)buffer; +assert(sizeof(CONN_SYN_8) == Min8(sizeof(CONN_SYN_8)) && "CONN_SYN_8 is not aligned to 8 bytes"); + +connSyn8->len = sizeof(CONN_SYN_8); + #ifdef ARCH_BE SwapBytes(connSyn8->len); #endif -assert(sizeof(CONN_SYN_8) == Min8(sizeof(CONN_SYN_8)) && "CONN_SYN_8 is not aligned to 8 bytes"); - -connSyn8->len = sizeof(CONN_SYN_8); strncpy((char*)connSyn8->type, "CONN_SYN", IA_MAX_TYPE_LEN); strncpy((char*)connSyn8->login, login.c_str(), IA_LOGIN_LEN); connSyn8->dirs = 0; @@ -734,18 +735,13 @@ for (int i = 0; i < DIR_NUM; i++) { connSyn8->dirs |= (selectedDirs[i] << i); } -return connSyn8->len; +return sizeof(CONN_SYN_8); } //--------------------------------------------------------------------------- int IA_CLIENT_PROT::Prepare_CONN_ACK_8(char * buffer) { connAck8 = (CONN_ACK_8*)buffer; -#ifdef ARCH_BE -SwapBytes(connAck8->len); -SwapBytes(connAck8->rnd); -#endif - assert(sizeof(CONN_ACK_8) == Min8(sizeof(CONN_ACK_8)) && "CONN_ACK_8 is not aligned to 8 bytes"); connAck8->len = sizeof(CONN_ACK_8); @@ -754,18 +750,18 @@ strncpy((char*)connAck8->type, "CONN_ACK", IA_MAX_TYPE_LEN); rnd++; connAck8->rnd = rnd; -return connAck8->len; +#ifdef ARCH_BE +SwapBytes(connAck8->len); +SwapBytes(connAck8->rnd); +#endif + +return sizeof(CONN_ACK_8); } //--------------------------------------------------------------------------- int IA_CLIENT_PROT::Prepare_ALIVE_ACK_8(char * buffer) { aliveAck8 = (ALIVE_ACK_8*)buffer; -#ifdef ARCH_BE -SwapBytes(aliveAck8->len); -SwapBytes(aliveAck8->rnd); -#endif - assert(Min8(sizeof(ALIVE_ACK_8)) == sizeof(ALIVE_ACK_8) && "ALIVE_ACK_8 is not aligned to 8 bytes"); aliveAck8 = (ALIVE_ACK_8*)buffer; @@ -773,42 +769,50 @@ aliveAck8->len = sizeof(ALIVE_ACK_8); strncpy((char*)aliveAck8->loginS, login.c_str(), IA_LOGIN_LEN); strncpy((char*)aliveAck8->type, "ALIVE_ACK", IA_MAX_TYPE_LEN); aliveAck8->rnd = ++rnd; -return aliveAck8->len; + +#ifdef ARCH_BE +SwapBytes(aliveAck8->len); +SwapBytes(aliveAck8->rnd); +#endif + +return sizeof(ALIVE_ACK_8); } //--------------------------------------------------------------------------- int IA_CLIENT_PROT::Prepare_DISCONN_SYN_8(char * buffer) { disconnSyn8 = (DISCONN_SYN_8*)buffer; +assert(Min8(sizeof(DISCONN_SYN_8)) == sizeof(DISCONN_SYN_8) && "DISCONN_SYN_8 is not aligned to 8 bytes"); + +disconnSyn8->len = sizeof(DISCONN_SYN_8); + #ifdef ARCH_BE SwapBytes(disconnSyn8->len); #endif -assert(Min8(sizeof(DISCONN_SYN_8)) == sizeof(DISCONN_SYN_8) && "DISCONN_SYN_8 is not aligned to 8 bytes"); - -disconnSyn8->len = sizeof(DISCONN_SYN_8); strncpy((char*)disconnSyn8->loginS, login.c_str(), IA_LOGIN_LEN); strncpy((char*)disconnSyn8->type, "DISCONN_SYN", IA_MAX_TYPE_LEN); strncpy((char*)disconnSyn8->login, login.c_str(), IA_LOGIN_LEN); -return disconnSyn8->len; +return sizeof(DISCONN_SYN_8); } //--------------------------------------------------------------------------- int IA_CLIENT_PROT::Prepare_DISCONN_ACK_8(char * buffer) { disconnAck8 = (DISCONN_ACK_8*)buffer; +assert(Min8(sizeof(DISCONN_ACK_8)) == sizeof(DISCONN_ACK_8) && "DISCONN_ACK_8 is not aligned to 8 bytes"); + +disconnAck8->len = Min8(sizeof(DISCONN_ACK_8)); +disconnAck8->rnd = rnd + 1; + #ifdef ARCH_BE SwapBytes(disconnAck8->len); SwapBytes(disconnAck8->rnd); #endif -assert(Min8(sizeof(DISCONN_ACK_8)) == sizeof(DISCONN_ACK_8) && "DISCONN_ACK_8 is not aligned to 8 bytes"); - -disconnAck8->len = Min8(sizeof(DISCONN_ACK_8)); -disconnAck8->rnd = rnd + 1; strncpy((char*)disconnAck8->loginS, login.c_str(), IA_LOGIN_LEN); strncpy((char*)disconnAck8->type, "DISCONN_ACK", IA_MAX_TYPE_LEN); -return disconnAck8->len; +return Min8(sizeof(DISCONN_ACK_8)); } //--------------------------------------------------------------------------- void IA_CLIENT_PROT::SetStatusChangedCb(tpStatusChangedCb p, void * data) -- 2.44.2