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));
}
}
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?
Re: memory allocation related
Quote:
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
Re: memory allocation related
Quote:
// 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?
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);
}
}
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.