Browse Source

no segfalts anymore
@FlorianPalm : please review //FIXME parts of the commit

Stasik0 10 years ago
parent
commit
181d37b41d
5 changed files with 26 additions and 7 deletions
  1. 4 0
      .gitignore
  2. 1 1
      examples/src/opcuaServer.c
  3. 2 2
      src/opcua_basictypes.c
  4. 17 4
      src/opcua_secureChannelLayer.c
  5. 2 0
      src/opcua_transportLayer.c

+ 4 - 0
.gitignore

@@ -50,4 +50,8 @@ tool/opcua.c
 tool/opcua.h
 tool/opcua_namespace_0.c
 tool/opcua_namespace_0.h
+include/opcua.h
+include/opcua_namespace_0.h
+src/opcua.c
+src/opcua_namespace_0.c
 

+ 1 - 1
examples/src/opcuaServer.c

@@ -57,7 +57,7 @@ void server_run()
 {
 	UA_connection connection;
 
-	UA_ByteString slMessage;
+	UA_ByteString slMessage = {NULL,0};
 
 	char optval = 1;
 	int sockfd, newsockfd, portno, clilen;

+ 2 - 2
src/opcua_basictypes.c

@@ -327,8 +327,8 @@ UA_Int32 UA_String_compare(UA_String* string1, UA_String* string2) {
 	return retval;
 }
 void UA_String_printf(char* label, UA_String* string) {
-	printf("%s {Length=%d, Data=%.*s}\n", label, string->length,
-			(char*) string->data);
+	printf("%s {Length=%d, Data=%s}\n", label, string->length,
+			(char*)string->data);
 }
 void UA_String_printx(char* label, UA_String* string) {
 	int i;

+ 17 - 4
src/opcua_secureChannelLayer.c

@@ -6,6 +6,7 @@
  */
 #include <stdio.h>
 #include <memory.h> // memcpy
+#include "opcua_transportLayer.h"
 #include "opcua_secureChannelLayer.h"
 
 #define SIZE_SECURECHANNEL_HEADER 12
@@ -257,11 +258,15 @@ UA_Int32 SL_openSecureChannel(UA_connection *connection,
 
 	response.length = sizeResponseType + sizeRespHeader + sizeRespMessage;
 
+	//FIXME: Sten 4 bytes are missing
+	response.length += 4;
+
 	//get memory for response
-	UA_alloc(&(response.data), UA_NodeId_calcSize(&responseType) + sizeRespHeader + sizeRespMessage);
+	UA_alloc((void*)&(response.data), response.length);
 	pos = 0;
 	//encode responseType (NodeId)
 	UA_NodeId_printf("SL_openSecureChannel - TypeId =",&responseType);
+
 	UA_NodeId_encode(&responseType, &pos, response.data);
 
 	//encode header
@@ -285,6 +290,11 @@ UA_Int32 SL_openSecureChannel(UA_connection *connection,
 	UA_ByteString_encode(&serverNonce, &pos,response.data);
 
 	printf("SL_openSecureChannel - response.length = %d \n",response.length);
+
+	printf("-----> reserved: %i\n", response.length);
+	printf("-----> encoded: %i\n", pos);
+	//FIXME: Sten: here is a problem
+
 	//449 = openSecureChannelResponse
 	SL_send(connection, response, 449);
 
@@ -341,6 +351,9 @@ UA_Int32 SL_processMessage(UA_connection *connection, UA_ByteString message) {
 		 * to the definition in part 4 */
 		// 	Req-1) RequestHeader requestHeader
 		UA_RequestHeader requestHeader;
+		UA_ExtensionObject additionalHeader;
+		//FIXME: Sten the structure was empty and decode attempted to fill it -> segfault
+		requestHeader.additionalHeader = &additionalHeader;
 		// 	Req-2) UInt32 ClientProtocolVersion
 		UA_UInt32 clientProtocolVersion;
 		// 	Req-3) Enum SecurityTokenRequestType requestType
@@ -348,12 +361,11 @@ UA_Int32 SL_processMessage(UA_connection *connection, UA_ByteString message) {
 		// 	Req-4) Enum MessageSecurityMode SecurityMode
 		UA_Int32 securityMode;
 		//  Req-5) ByteString ClientNonce
-		UA_ByteString clientNonce;
+		UA_ByteString clientNonce = {0, NULL};
 		//  Req-6) Int32 RequestLifetime
 		UA_Int32 requestedLifetime;
 
 		UA_ByteString_printx("SL_processMessage - message=", &message);
-
 		// Req-1) RequestHeader requestHeader
 		UA_RequestHeader_decode(message.data, &pos, &requestHeader);
 		UA_String_printf("SL_processMessage - requestHeader.auditEntryId=",
@@ -429,7 +441,8 @@ UA_Int32 SL_processMessage(UA_connection *connection, UA_ByteString message) {
 				&clientNonce);
 		UA_ByteString_printf("SL_processMessage - clientNonce=", &clientNonce);
 
-		UA_ByteString_delete(&clientNonce);
+		//deleteMembers is important since clientNonce is on stack
+		UA_ByteString_deleteMembers(&clientNonce);
 
 		//  Req-6) Int32 RequestLifetime
 		UA_Int32_decode(message.data, &pos,

+ 2 - 0
src/opcua_transportLayer.c

@@ -286,6 +286,8 @@ UA_Int32 TL_send(UA_connection *connection, UA_ByteString *packet)
 		//server error
 	}
 
+	return UA_SUCCESS;
+
 }