-
February 20th, 2018, 10:22 AM
#1
memory allocation related
Hi,
Code:
typedef struct structAuthDelivery
{
u32 nSig; // For message integrity purposes.
AuthSetRes eRes;
char pzIMSI[20];
u32 nMMHandle;
u32 nNumVectors;
} AuthDelivery;
function()
{
CSignal sSig;
AuthDelivery * pAuth = (AuthDelivery*)(sSig.Alloc(0));
if (pAuthInfo)
{
list<CDiaAVP *> lGroup;
if (m_eRATType == RANTypeEUTRAN || m_eRATType == RANTypeIMS)
{
pAuthInfo->FindAllSameAVPs(DiameterVendorId3GPP, AVP3GPP_EUTRANVector, lGroup);
}
else
{
pAuthInfo->FindAllSameAVPs(DiameterVendorId3GPP, AVP3GPP_UTRANVector, lGroup);
}
LogTrace(<< "Auth info contained num of vectors: " << lGroup.size())
list<CDiaAVP*>::iterator iIter = lGroup.begin();
while (nNumVectors < 5 && iIter != lGroup.end())
{
CDiaAVP * pAuthvector = *iIter;
CDiaAVP * pField = pAuthvector->FindAVP(DiameterVendorId3GPP, AVP3GPP_RAND);
if (pField)
{
if (pField->GetOctetStringLen() >= 16)
{
AuthVector pVector = (AuthVector*)(((u8*)pAuth) + sizeof(AuthDelivery));
memcpy((void *)&(pVector->aRAND[0]), pField->GetOctetStringPtr(), 16);
}
}
:
nNumVectors++;
iIter++;
}
pAuth->nNumVectors = nNumVectors;
}
sSig.Post(SigMsgAuthDelivery, m_sDeliveryAddr, SigAddr(SigModDiaConn, 0));
}
Currently I am trying to change the above pseudocode (legacy), based on flag, i either fill the sSig Or a new struct.
Code:
function()
{
CSignal sSig;
// new flag m_bFromAdmin
if(m_bFromAdmin)
{
AuthDelivery sAuthDel;
AuthDelivery * pAuth = &sAuthDel;
}
else
{
AuthDelivery * pAuth = (AuthDelivery*)(sSig.Alloc(0));
pAuth->nSig = AuthDeliverySig;
pAuth->eRes = m_bDoingResync?AuthSetResResyncOk:AuthSetResOk;
pAuth->nMMHandle = m_sDeliveryAddr.second;
strcpy(pAuth->pzIMSI, m_sIMSI.c_str());
}
if (pAuthInfo)
{
list<CDiaAVP *> lGroup;
if (m_eRATType == RANTypeEUTRAN || m_eRATType == RANTypeIMS)
{
pAuthInfo->FindAllSameAVPs(DiameterVendorId3GPP, AVP3GPP_EUTRANVector, lGroup);
}
else
{
pAuthInfo->FindAllSameAVPs(DiameterVendorId3GPP, AVP3GPP_UTRANVector, lGroup);
}
LogTrace(<< "Auth info contained num of vectors: " << lGroup.size())
list<CDiaAVP*>::iterator iIter = lGroup.begin();
while (nNumVectors < 5 && iIter != lGroup.end())
{
CDiaAVP * pAuthvector = *iIter;
CDiaAVP * pField = pAuthvector->FindAVP(DiameterVendorId3GPP, AVP3GPP_RAND);
if (pField)
{
if (pField->GetOctetStringLen() >= 16)
{
AuthVector * pVector;
if(m_bFromAdmin)
{
// Best way to allocate this memory, so pVector now holds the first vector
pVector = ;
}
else
{
pVector = (AuthVector*)(((u8*)pAuth) + sizeof(AuthDelivery));
}
memcpy((void *)&(pVector->aRAND[0]), pField->GetOctetStringPtr(), 16);
}
}
:
nNumVectors++;
iIter++;
}
pAuth->nNumVectors = nNumVectors;
}
if(m_bFromAdmin)
{
CGetSubsInfoVLR::HandleAuthVectorResponse(m_req, m_sIMSI, m_sUniqueId, pAuth, VLRQueryRespSuccess, DataType4G);
}
else
{
sSig.Post(SigMsgAuthDelivery, m_sDeliveryAddr, SigAddr(SigModDiaConn, 0));
}
}
-
February 20th, 2018, 11:46 AM
#2
Re: memory allocation related
Code:
if (m_bFromAdmin)
{
AuthDelivery sAuthDel;
AuthDelivery * pAuth = &sAuthDel;
} else
...
Why have this - when sAuthDel and pAuth are only valid within the {..} scope and aren't used before they go out of scope?
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
February 20th, 2018, 11:54 AM
#3
Re: memory allocation related
Originally Posted by 2kaud
Code:
if (m_bFromAdmin)
{
AuthDelivery sAuthDel;
AuthDelivery * pAuth = &sAuthDel;
} else
...
Why have this - when sAuthDel and pAuth are only valid within the {..} scope and aren't used before they go out of scope?
yes, sorry, it was typo in my pseudocode. It can be changed to something like
AuthDelivery sAuthDel;
AuthDelivery * pAuth;
if (m_bFromAdmin)
{
AuthDelivery * pAuth = &sAuthDel;
} else
-
February 20th, 2018, 12:29 PM
#4
Re: memory allocation related
// Best way to allocate this memory, so pVector now holds the first vector
pVector = ;
First vector of what? If not bFromAdmin then pVector points to index 1 from pAuth (second entry). But if bFromAdmin is true then pAuth just points to the memory for sAuthDev which is *AuthDelivery. What is the relation between AuthDelivery and AuthVector? Is AuthVector an array of AuthDelivery?
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
February 21st, 2018, 03:58 AM
#5
Re: memory allocation related
@kaud: thanks a lot for the response .
Legacy code they use the "AuthVector" after the "Authdelivery". Lets say Authdelivery has nNumVectors =2. There will be two Authvector structs after the Auth delivery.
Like in the handler for this response is somewhat like this:
Code:
void CGetSubsInfoVLR::HandleAuthVectorResponse(Quortus::Oam2::IRequestPtr const &req, const std::string& sIMSI, const std::string& sUniqueId, AuthDelivery * pAuthDel, VLRQueryResponse eVLRQueryResponse, AuthVectorDataType eRATType)
{
if(pAuthDel->eRes == AuthSetResOk && eVLRQueryResponse == VLRQueryRespSuccess)
{
AuthVector * pVector = (AuthVector*)(((u8*)pAuthDel) + sizeof(AuthDelivery));
for (u8 nI = 0; nI < pAuthDel->nNumVectors && nI < 10; nI++, pVector++)
{
LogTraceS("HandleAuthVectorResponse",<< "Vector[" << (u16) nI << "]: " << " bIsQuintuplet: " << pVector->bIsQuintuplet);
OAM::Data::VLR::Summary data;
COctetArrayType sRand(pVector->aRAND, nRAND_SIZE);
}
}
Last edited by pdk5; February 21st, 2018 at 04:04 AM.
-
February 21st, 2018, 06:40 AM
#6
Re: memory allocation related
@ kaud: It looks like error in the legacy code, as it looks like overwrites the auth vectors when they are more than one. I think it was tested only with one vector.
I changed the numVectors to 1 and the response fields were ok.
Now i need to find out the better way of passing the multiple auth vectors back to handler.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|