Переглянути джерело

Add checks to generateNonce

Since this is a public funciton parameters should be verified.
Furthermore if 0 was passed an error would occur, since the
data pointer was 0 and the return value of the alloc functio wasn't checked.
Now 0 length nonces can be 'generated'.
Mark 7 роки тому
батько
коміт
fdd5efcd64
1 змінених файлів з 10 додано та 3 видалено
  1. 10 3
      src/ua_securechannel.c

+ 10 - 3
src/ua_securechannel.c

@@ -120,9 +120,16 @@ UA_StatusCode
 UA_SecureChannel_generateNonce(const UA_SecureChannel *const channel,
                                const size_t nonceLength,
                                UA_ByteString *const nonce) {
-    UA_ByteString_allocBuffer(nonce, nonceLength);
-    if(!nonce->data)
-        return UA_STATUSCODE_BADOUTOFMEMORY;
+    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)
+        return retval;
 
     return channel->securityPolicy->symmetricModule.generateNonce(channel->securityPolicy,
                                                                   nonce);