Skip to content

Commit 4676c8c

Browse files
authored
CDRIVER-5634 account for embedded NULL when copying salt (#1700)
* CDRIVER-5634 account for embedded NULL when copying `salt` * remove unnecessary casts
1 parent 43151b1 commit 4676c8c

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/libmongoc/src/mongoc/mongoc-crypto-cng.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,13 +176,15 @@ _bcrypt_derive_key_pbkdf2 (BCRYPT_ALG_HANDLE prf,
176176
}
177177

178178
// Make non-const versions of password and salt.
179-
char *password_copy = bson_strndup (password, password_len);
180-
char *salt_copy = bson_strndup ((const char *) salt, salt_len);
179+
unsigned char *password_copy = bson_malloc (password_len);
180+
memcpy (password_copy, password, password_len);
181+
unsigned char *salt_copy = bson_malloc (salt_len);
182+
memcpy (salt_copy, salt, salt_len);
181183

182184
NTSTATUS status = BCryptDeriveKeyPBKDF2 (prf,
183-
(unsigned char *) password_copy,
185+
password_copy,
184186
(ULONG) password_len,
185-
(unsigned char *) salt_copy,
187+
salt_copy,
186188
(ULONG) salt_len,
187189
(ULONGLONG) iterations,
188190
output,

0 commit comments

Comments
 (0)