-
Notifications
You must be signed in to change notification settings - Fork 589
Description
The libssh2_userauth_publickey_frommemory()
function accepts private key data in the form of an arbitrary buffer and its length. From the documentation for libssh2_userauth_publickey_frommemory()
:
privatekeydata
- Buffer containing the contents of a private key file.
privatekeydata_len
- Length of private key data.
... but that buffer is passed down the chain via the filename
member of a struct privkey_file
:
Lines 1815 to 1820 in f6694be
struct privkey_file privkey_file; | |
void *abstract = &privkey_file; | |
int rc; | |
privkey_file.filename = privatekeydata; | |
privkey_file.passphrase = passphrase; |
When that buffer is ultimately processed by sign_frommemory()
, the originally-provided buffer length has been effectively discarded, and its length is instead calculated as if it were a string using strlen()
:
Lines 830 to 835 in f6694be
rc = memory_read_privatekey(session, &privkeyobj, &hostkey_abstract, | |
session->userauth_pblc_method, | |
session->userauth_pblc_method_len, | |
pk_file->filename, | |
strlen(pk_file->filename), | |
pk_file->passphrase); |
Depending on the size of the block and memory garbage, this will overread the buffer and give nondeterministic results.