Mark преди 7 години
родител
ревизия
6cd8c3e1c4
променени са 4 файла, в които са добавени 14 реда и са изтрити 15 реда
  1. 11 6
      plugins/ua_securitypolicy_none.c
  2. 0 3
      src/ua_securechannel.c
  3. 1 5
      tests/check_securechannel.c
  4. 2 1
      tests/testing-plugins/testing_policy.c

+ 11 - 6
plugins/ua_securitypolicy_none.c

@@ -1,6 +1,7 @@
 /* This work is licensed under a Creative Commons CCZero 1.0 Universal License.
  * See http://creativecommons.org/publicdomain/zero/1.0/ for more information. */
 
+#include "ua_types.h"
 #include "ua_securitypolicy_none.h"
 #include "ua_types_generated_handling.h"
 
@@ -64,11 +65,15 @@ generateKey_none(const UA_SecurityPolicy *securityPolicy,
 static UA_StatusCode
 generateNonce_none(const UA_SecurityPolicy *securityPolicy,
                    UA_ByteString *out) {
-    out->data = UA_Byte_new();
-    if(!out->data)
-        return UA_STATUSCODE_BADOUTOFMEMORY;
-    out->length = 1;
-    out->data[0] = 'a';
+    if(securityPolicy == NULL || out == NULL)
+        return UA_STATUSCODE_BADINTERNALERROR;
+    if(out->length != 0)
+        return UA_STATUSCODE_BADINTERNALERROR;
+
+    if(out->data != NULL)
+        UA_ByteString_deleteMembers(out);
+
+    out->data = (UA_Byte *) UA_EMPTY_ARRAY_SENTINEL;
     return UA_STATUSCODE_GOOD;
 }
 
@@ -114,7 +119,7 @@ policy_deletemembers_none(UA_SecurityPolicy *policy) {
 UA_StatusCode
 UA_SecurityPolicy_None(UA_SecurityPolicy *policy, const UA_ByteString localCertificate,
                        UA_Logger logger) {
-    policy->policyContext = (void*)(uintptr_t)logger;
+    policy->policyContext = (void *) (uintptr_t) logger;
     policy->policyUri = UA_STRING("http://opcfoundation.org/UA/SecurityPolicy#None");
     policy->logger = logger;
     UA_ByteString_copy(&localCertificate, &policy->localCertificate);

+ 0 - 3
src/ua_securechannel.c

@@ -125,9 +125,6 @@ UA_SecureChannel_generateNonce(const UA_SecureChannel *const channel,
     if(channel == NULL || nonce == NULL)
         return UA_STATUSCODE_BADINTERNALERROR;
 
-    if(nonceLength == 0)
-        return UA_STATUSCODE_GOOD;
-
     UA_ByteString_deleteMembers(nonce);
     UA_StatusCode retval = UA_ByteString_allocBuffer(nonce, nonceLength);
     if(retval != UA_STATUSCODE_GOOD)

+ 1 - 5
tests/check_securechannel.c

@@ -464,11 +464,7 @@ START_TEST(SecureChannel_generateNonce)
 
             ck_assert_msg(retval == UA_STATUSCODE_GOOD, "Expected retval to be good");
             ck_assert_msg(myNonce.length == i, "Expected nonce length to be %i but was %i", i, myNonce.length);
-            if(i != 0)
-                ck_assert_msg(fCalled.generateNonce, "Expected generateNonce to have been called");
-            else
-                if(fCalled.generateNonce)
-                    printf("generateNonce was called with nonceLength = 0. Could possibly be avoided");
+            ck_assert_msg(fCalled.generateNonce, "Expected generateNonce to have been called");
         }
 
         UA_ByteString_deleteMembers(&myNonce);

+ 2 - 1
tests/testing-plugins/testing_policy.c

@@ -197,7 +197,8 @@ generateNonce_testing(const UA_SecurityPolicy *securityPolicy,
                       UA_ByteString *out) {
     ck_assert(securityPolicy != NULL);
     ck_assert(out != NULL);
-    ck_assert(out->data != NULL);
+    if(out->length != 0)
+        ck_assert(out->data != NULL);
 
     memset(out->data, 'N', out->length);