Browse Source

fixing null pointer bugs

open62541 11 years ago
parent
commit
21f0205d5d

+ 6 - 4
src/ua_stack_channel.c

@@ -195,7 +195,9 @@ UA_Int32 SL_Channel_new(SL_secureChannel *channel,
 
 {
 	UA_Int32 retval = UA_SUCCESS;
+	retval |= UA_alloc((void**)&channel,sizeof(SL_secureChannel));
 	retval |= UA_alloc((void**)channel,sizeof(SL_Channel1));
+
 	SL_Channel1 *thisChannel = (SL_Channel1*)(*channel);
 
 	thisChannel->channelIdProvider = channelIdProvider;
@@ -255,6 +257,9 @@ UA_Int32 SL_Channel_initByRequest(SL_secureChannel channel,
 	channel->lastRequestId = sequenceHeader->requestId;
 	channel->lastSequenceNumber = sequenceHeader->sequenceNumber;
 
+	channel->requestId = channel->lastRequestId;
+	channel->sequenceNumber = channel->lastSequenceNumber;
+
 	channel->state = UA_SL_CHANNEL_CLOSED;
 
 	return UA_SUCCESS;
@@ -360,7 +365,6 @@ UA_Int32 SL_Channel_processOpenRequest(SL_secureChannel channel,
 			break;
 		}
 	}
-
 	switch (request->securityMode)
 	{
 	case UA_SECURITYMODE_INVALID:
@@ -396,10 +400,8 @@ UA_Int32 SL_Channel_processOpenRequest(SL_secureChannel channel,
 	}
 
 	response->serverProtocolVersion = protocolVersion;
-	SL_Channel_getChannelId(channel,&response->securityToken.channelId);
 
-	SL_Channel_getTokenId(channel, &response->securityToken.tokenId);
-	SL_Channel_getRevisedLifetime(channel, &response->securityToken.revisedLifetime);
+	UA_ChannelSecurityToken_copy(&((SL_Channel1*)(channel))->securityToken, &(response->securityToken));
 
 	UA_ByteString_copy(&thisChannel->localNonce, &response->serverNonce);
 

+ 25 - 16
src/ua_stack_channel_manager.c

@@ -35,7 +35,7 @@ UA_Int32 SL_ChannelManager_newChannelByRequest(UA_Int32 connectionId, const UA_B
 UA_Int32 SL_ChannelManager_init(UA_UInt32 maxChannelCount,UA_UInt32 tokenLifetime, UA_UInt32 startChannelId, UA_UInt32 startTokenId, UA_String *endpointUrl)
 {
 	UA_alloc((void**)&channelManager,sizeof(SL_ChannelManager));
-	UA_indexedList_init(&(channelManager->channels));
+	UA_list_init(&(channelManager->channels));
 	channelManager->lastChannelId = startChannelId;
 	channelManager->lastTokenId = startTokenId;
 	UA_String_copy(endpointUrl,&channelManager->endpointUrl);
@@ -45,16 +45,23 @@ UA_Int32 SL_ChannelManager_init(UA_UInt32 maxChannelCount,UA_UInt32 tokenLifetim
 	return UA_SUCCESS;
 }
 
-UA_Int32 SL_ChannelManager_addChannel(SL_secureChannel channel)
+UA_Int32 SL_ChannelManager_addChannel(SL_secureChannel *channel)
 {
-	if (channelManager->maxChannelCount < channelManager->currentChannelCount)
+	if (channelManager->maxChannelCount > channelManager->currentChannelCount)
 	{
 //TODO lock access (mulitthreading)------------
-		UA_list_addPayloadToBack(&channelManager->channels,(void*)channel);
+		UA_list_Element *element;
+		UA_alloc((void**)&element, sizeof(UA_list_Element));
+		UA_list_initElement(element);
+		element->payload =(void*) channel;
+
+		UA_list_addElementToBack(&channelManager->channels,element);
+		return UA_SUCCESS;
 		//set id in channel object which was added
 //TODO lock access------------
 	}
-	return UA_SUCCESS;
+	return UA_ERROR;
+
 }
 
 UA_Int32 generateNewTokenId()
@@ -132,7 +139,7 @@ UA_Int32 SL_ChannelManager_updateChannels()
 			//remove channels with expired lifetime, close linked list
 			if (channel)
 			{
-
+				UA_list_addPayloadToBack(&channelManager->channels,(void*)channel);
 				SL_Channel_getRemainingLifetime(*channel,&channelLifetime);
 				if(channelLifetime <= 0)
 				{
@@ -177,25 +184,27 @@ UA_Int32 SL_ChannelManager_getChannelLifeTime(UA_DateTime *lifeTime)
 	return UA_SUCCESS;
 }
 
-UA_Int32 SL_ChannelManager_getChannelsByConnectionId(UA_Int32 connectionId,
+/*UA_Int32 SL_ChannelManager_getChannelsByConnectionId(UA_Int32 connectionId,
 		SL_secureChannel **channels, UA_Int32 *noOfChannels)
 {
-	return UA_SUCCESS;
+	return UA_SUCCESS;UA_list_Element
 }
-
+*/
 UA_Int32 SL_ChannelManager_getChannel(UA_UInt32 channelId, SL_secureChannel *channel)
 {
-	UA_list_Element* current = channelManager->channels.first;
+	UA_UInt32 tmpChannelId;
+ 	UA_list_Element* current = channelManager->channels.first;
 	while (current)
 	{
 		if (current->payload)
 		{
-			UA_indexedList_Element* elem =
-					(UA_indexedList_Element*) current->payload;
-			*channel = (SL_secureChannel) elem->payload;
-
-			return UA_SUCCESS;
-
+			UA_list_Element* elem = (UA_list_Element*) current;
+			*channel = *((SL_secureChannel*) (elem->payload));
+			SL_Channel_getChannelId(*channel, &tmpChannelId);
+		 	if(tmpChannelId == channelId)
+		 	{
+		 		return UA_SUCCESS;
+		 	}
 		}
 	}
 	*channel = UA_NULL;

+ 1 - 1
src/ua_stack_channel_manager.h

@@ -17,7 +17,7 @@ typedef struct SL_ChannelManager *SL_secureChannelManager;
 
 
 UA_Int32 SL_ChannelManager_init(UA_UInt32 maxChannelCount,UA_UInt32 tokenLifetime, UA_UInt32 startChannelId, UA_UInt32 startTokenId, UA_String *endpointUrl);
-UA_Int32 SL_ChannelManager_addChannel(SL_secureChannel channel);
+UA_Int32 SL_ChannelManager_addChannel(SL_secureChannel *channel);
 //UA_Int32 SL_ChannelManager_renewChannelToken(UA_Int32 channelId, UA_DateTime requestedLifeTime);
 //UA_Int32 SL_ChannelManager_createChannelToken(SL_secureChannel channel);
 //UA_Int32 SL_ChannelManager_renewChannelToken(SL_secureChannel channel);

+ 7 - 5
src/ua_transport_binary.c

@@ -119,7 +119,9 @@ static UA_Int32 TL_handleHello(TL_Connection* connection, const UA_ByteString* m
 static UA_Int32 TL_handleOpen(UA_TL_Connection1 connection, const UA_ByteString* msg, UA_Int32* pos) {
 	UA_Int32 state;
 	UA_TL_Connection_getState(connection,&state);
-	SL_secureChannel channel = UA_NULL;
+	SL_secureChannel *channel = UA_NULL;
+
+
 
 	UA_ByteString receiverCertificateThumbprint;
 	UA_ByteString securityPolicyUri;
@@ -127,7 +129,7 @@ static UA_Int32 TL_handleOpen(UA_TL_Connection1 connection, const UA_ByteString*
 
 	if (state == CONNECTIONSTATE_ESTABLISHED) {
 
-
+//TODO get this from initialization
 		UA_alloc((void**)&receiverCertificateThumbprint.data, -1);
 		UA_alloc((void**)&securityPolicyUri.data, 47);
 		UA_alloc((void**)&senderCertificate.data, 0);
@@ -141,7 +143,7 @@ static UA_Int32 TL_handleOpen(UA_TL_Connection1 connection, const UA_ByteString*
 		senderCertificate.data = UA_NULL;
 		senderCertificate.length = 0;
 
-		SL_Channel_new(&channel,
+		SL_Channel_new(channel,
 				SL_ChannelManager_generateChannelId,
 				SL_ChannelManager_generateToken,
 				&receiverCertificateThumbprint,
@@ -152,9 +154,9 @@ static UA_Int32 TL_handleOpen(UA_TL_Connection1 connection, const UA_ByteString*
 
 	//return SL_Channel_new(connection, msg, pos);
 	//UA_TL_Connection_getId(connection,connectionId);
-		if(SL_Channel_initByRequest(channel,connection, msg, pos) == UA_SUCCESS)
+		if(SL_Channel_initByRequest(*channel,connection, msg, pos) == UA_SUCCESS)
 		{
-			SL_ProcessOpenChannel(channel, msg, pos);
+			SL_ProcessOpenChannel(*channel, msg, pos);
 			SL_ChannelManager_addChannel(channel);
 		}else
 		{

+ 4 - 3
src/ua_transport_binary_secure.c

@@ -38,6 +38,7 @@ static UA_Int32 SL_Send(SL_secureChannel channel,
 	if (isAsym)
 	{
 
+		SL_Channel_getLocalAsymAlgSettings(channel, &asymAlgSettings);
 		UA_ByteString_newMembers((UA_ByteString *) response_gather[0],
 				SIZE_SECURECHANNEL_HEADER + SIZE_SEQHEADER_HEADER
 						+ UA_AsymmetricAlgorithmSecurityHeader_calcSize(
@@ -54,7 +55,7 @@ static UA_Int32 SL_Send(SL_secureChannel channel,
 	// sizeSignature = 0;
 	UA_ByteString *header = (UA_ByteString *) response_gather[0];
 
-	/*---encode Secure Conversation Message Header ---*/
+	/*---encode Secure Conversation Message HeaService_CreateSessionder ---*/
 	if (isAsym)
 	{
 		header->data[0] = 'O';
@@ -83,7 +84,7 @@ static UA_Int32 SL_Send(SL_secureChannel channel,
 	if (isAsym)
 	{
 
-		SL_Channel_getLocalAsymAlgSettings(channel, &asymAlgSettings);
+
 		UA_AsymmetricAlgorithmSecurityHeader_encodeBinary(asymAlgSettings, &pos,
 				header);
 		UA_free(asymAlgSettings);
@@ -313,7 +314,7 @@ UA_Int32 SL_Process(const UA_ByteString* msg,
 	UA_SymmetricAlgorithmSecurityHeader_decodeBinary(msg, pos,
 			&symAlgSecHeader);
 
-	if (SL_ChannelManager_getChannel(secureChannelId,
+ 	if (SL_ChannelManager_getChannel(secureChannelId,
 			&channel) == UA_SUCCESS)
 	{