Fix fixed dictionary sizes in apple crypto key generation
authorKevin Jones <kevin@vcsjones.com>
Fri, 29 May 2020 21:58:04 +0000 (17:58 -0400)
committerGitHub <noreply@github.com>
Fri, 29 May 2020 21:58:04 +0000 (14:58 -0700)
Both dictionaries had a fixed size of two, however three items were being added to it.
This is undefined behavior in the documentation.

src/libraries/Native/Unix/System.Security.Cryptography.Native.Apple/pal_ecc.c
src/libraries/Native/Unix/System.Security.Cryptography.Native.Apple/pal_rsa.c

index 86743f1..6bb8eae 100644 (file)
@@ -16,7 +16,7 @@ int32_t AppleCryptoNative_EccGenerateKey(
     if (pPublicKey == NULL || pPrivateKey == NULL || pOSStatus == NULL)
         return kErrorBadInput;
 
-    CFMutableDictionaryRef attributes = CFDictionaryCreateMutable(NULL, 2, &kCFTypeDictionaryKeyCallBacks, NULL);
+    CFMutableDictionaryRef attributes = CFDictionaryCreateMutable(NULL, 3, &kCFTypeDictionaryKeyCallBacks, NULL);
 
     CFNumberRef cfKeySizeValue = CFNumberCreate(NULL, kCFNumberIntType, &keySizeBits);
     OSStatus status;
index 2e2568a..7ad02d7 100644 (file)
@@ -21,7 +21,7 @@ int32_t AppleCryptoNative_RsaGenerateKey(
     if (keySizeBits < 384 || keySizeBits > 16384)
         return -2;
 
-    CFMutableDictionaryRef attributes = CFDictionaryCreateMutable(NULL, 2, &kCFTypeDictionaryKeyCallBacks, NULL);
+    CFMutableDictionaryRef attributes = CFDictionaryCreateMutable(NULL, 3, &kCFTypeDictionaryKeyCallBacks, NULL);
 
     CFNumberRef cfKeySizeValue = CFNumberCreate(NULL, kCFNumberIntType, &keySizeBits);
     OSStatus status;