mirror of
https://github.com/libgit2/libgit2.git
synced 2026-01-25 11:06:32 +00:00
ssh: fix custom ssh heap buffer overflow
The `ssh_custom_free()` function calls `strlen()` on the `publickey` field, which stores binary data, not a null-terminated string. This causes a heap buffer overflow when the public key data is not null-terminated or contains embedded null bytes. The `publickey` field stores binary data, as required by the underlying `libssh2_userauth_publickey()` function, which accepts a public key parameter of the type `const unsigned char*`. Use the stored `publickey_len` instead of `strlen()` to determine the correct buffer size.
This commit is contained in:
@@ -161,7 +161,7 @@ static void ssh_custom_free(struct git_credential *cred)
|
||||
|
||||
if (c->publickey) {
|
||||
/* Zero the memory which previously held the publickey */
|
||||
size_t key_len = strlen(c->publickey);
|
||||
size_t key_len = c->publickey_len;
|
||||
git__memzero(c->publickey, key_len);
|
||||
git__free(c->publickey);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user