Browse Source

ua_types functionality of allocating strings was changed to be compliant with C++ string allocation (removes the compiler warning for -Wall); Fixed possible SEGFAULTS in subscriptions and method calls when the client issues non-standard compliant messages.

ichrispa 8 years ago
parent
commit
984342b057
3 changed files with 23 additions and 12 deletions
  1. 13 7
      include/ua_types.h
  2. 4 1
      src/server/ua_services_call.c
  3. 6 4
      src/server/ua_subscription.c

+ 13 - 7
include/ua_types.h

@@ -21,6 +21,9 @@ extern "C" {
 #endif
 
 #include <stdint.h>
+#include <string.h>
+#include <stdlib.h>
+#include <inttypes.h>
 #include <stdbool.h>
 #include "ua_config.h"
 #include "ua_constants.h"
@@ -216,9 +219,11 @@ UA_EXPORT extern const UA_String UA_STRING_NULL;
  * ``UA_STRING_ALLOC`` is shorthand for ``UA_String_fromChars`` and makes a copy
  * of the char-array. */
 static UA_INLINE UA_String
-UA_STRING(char *chars) {
+UA_STRING(const char *chars) {
     UA_String str; str.length = strlen(chars);
-    str.data = (UA_Byte*)chars; return str;
+    str.length = strlen(chars);
+    str.data = (UA_Byte *) malloc(str.length ); memcpy(str.data, chars, str.length ); 
+    return str;
 }
 
 #define UA_STRING_ALLOC(CHARS) UA_String_fromChars(CHARS)
@@ -290,7 +295,7 @@ UA_StatusCode UA_EXPORT UA_ByteString_allocBuffer(UA_ByteString *bs, size_t leng
 UA_EXPORT extern const UA_ByteString UA_BYTESTRING_NULL;
 
 static UA_INLINE UA_ByteString
-UA_BYTESTRING(char *chars) {
+UA_BYTESTRING( char *chars) {
     UA_ByteString str; str.length = strlen(chars);
     str.data = (UA_Byte*)chars; return str;
 }
@@ -420,7 +425,7 @@ UA_EXPANDEDNODEID_STRING_GUID(UA_UInt16 nsIndex, UA_Guid guid) {
 }
 
 static UA_INLINE UA_ExpandedNodeId
-UA_EXPANDEDNODEID_BYTESTRING(UA_UInt16 nsIndex, char *chars) {
+UA_EXPANDEDNODEID_BYTESTRING(UA_UInt16 nsIndex,  char *chars) {
     UA_ExpandedNodeId id; id.nodeId = UA_NODEID_BYTESTRING(nsIndex, chars);
     id.serverIndex = 0; id.namespaceUri = UA_STRING_NULL; return id;
 }
@@ -441,9 +446,10 @@ typedef struct {
 } UA_QualifiedName;
 
 static UA_INLINE UA_QualifiedName
-UA_QUALIFIEDNAME(UA_UInt16 nsIndex, char *chars) {
+UA_QUALIFIEDNAME(UA_UInt16 nsIndex, const char *chars) {
     UA_QualifiedName qn; qn.namespaceIndex = nsIndex;
-    qn.name = UA_STRING(chars); return qn;
+    qn.name.length = strlen(chars);
+    qn.name.data = (UA_Byte *) malloc(qn.name.length ); memcpy(qn.name.data, chars, qn.name.length ); return qn;
 }
 
 static UA_INLINE UA_QualifiedName
@@ -462,7 +468,7 @@ typedef struct {
 } UA_LocalizedText;
 
 static UA_INLINE UA_LocalizedText
-UA_LOCALIZEDTEXT(char *locale, char *text) {
+UA_LOCALIZEDTEXT( const char *locale,  const char *text) {
     UA_LocalizedText lt; lt.locale = UA_STRING(locale);
     lt.text = UA_STRING(text); return lt;
 }

+ 4 - 1
src/server/ua_services_call.c

@@ -26,7 +26,10 @@ getArgumentsVariableNode(UA_Server *server, const UA_MethodNode *ofMethod,
 
 static UA_StatusCode
 satisfySignature(UA_Server *server, const UA_Variant *var, const UA_Argument *arg) {
-    if(!UA_NodeId_equal(&var->type->typeId, &arg->dataType)){
+  if(var == NULL || var->type == NULL) 
+    return UA_STATUSCODE_BADINVALIDARGUMENT;
+  
+  if(!UA_NodeId_equal(&var->type->typeId, &arg->dataType)){
         if(!UA_NodeId_equal(&var->type->typeId, &UA_TYPES[UA_TYPES_INT32].typeId))
             return UA_STATUSCODE_BADINVALIDARGUMENT;
 

+ 6 - 4
src/server/ua_subscription.c

@@ -111,10 +111,12 @@ static void SampleCallback(UA_Server *server, UA_MonitoredItem *monitoredItem) {
             return;
         }
         MonitoredItem_queuedValue *queueItem = TAILQ_LAST(&monitoredItem->queue, QueueOfQueueDataValues);
-        TAILQ_REMOVE(&monitoredItem->queue, queueItem, listEntry);
-        UA_DataValue_deleteMembers(&queueItem->value);
-        UA_free(queueItem);
-        monitoredItem->currentQueueSize--;
+        if (queueItem != NULL) {
+          TAILQ_REMOVE(&monitoredItem->queue, queueItem, listEntry);
+          UA_DataValue_deleteMembers(&queueItem->value);
+          UA_free(queueItem);
+          monitoredItem->currentQueueSize--;
+        }
     }
 
     /* add the sample */