You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
NULL pointer dereferece issue in _libssh2_get_string() #802
Describe the bug
In function _libssh2_pub_priv_openssh_keyfilememory, decrypted pointer is NULL and when the function _libssh2_get_string() gets called[1], it will eventually
call the function _libssh2_check_length() in misc.c [2].
Here, it is not being checked whether the string_buf is
NULL or not.
It will cause a crash due to NULL pointer dereference.
_libssh2_get_string is only called if there was no error returned by
_libssh2_openssh_pem_parse_memory. Under what circumstances would that return
success yet still return a NULL string buffer? Can you provide a way to
reproduce this?
Hi @dfandrich
You are right, it will call _libssh2_get_string only there was no error
returned when called _libssh2_openssh_pem_parse_memory. but if you see _libssh2_openssh_pem_parse_memory function in pem.c, it will use decrypted_buf to call _libssh2_openssh_pem_parse_data (1) and in the
function _libssh2_openssh_pem_parse_data there is no assignment to decrypted_buf is happening apart from setting it to NULL (2). So if the
function _libssh2_openssh_pem_parse_memory doesn't return any error,
there is a chance of NULL pointer dereference.
I want to mention that I haven't tested this issue using any PoC, I am not
very good at constructing an exploit, I just found out while doing a code
review for adding libssh2 in MIR(main inclusion review) process (3) for Ubuntu.
I found another NULL pointer issue and it was already fixed here (4)
@dfandrich I also noted offline this seems hypothetical and not possible in the noted code path. That said, it would be good form to add a null check to _libssh2_get_string.
Activity
dfandrich commentedon Feb 23, 2023
nishitm commentedon Feb 23, 2023
Hi @dfandrich
You are right, it will call
_libssh2_get_stringonly there was no errorreturned when called
_libssh2_openssh_pem_parse_memory. but if you see_libssh2_openssh_pem_parse_memoryfunction in pem.c, it will usedecrypted_bufto call_libssh2_openssh_pem_parse_data(1) and in thefunction
_libssh2_openssh_pem_parse_datathere is no assignment todecrypted_bufis happening apart from setting it to NULL (2). So if thefunction
_libssh2_openssh_pem_parse_memorydoesn't return any error,there is a chance of NULL pointer dereference.
I want to mention that I haven't tested this issue using any PoC, I am not
very good at constructing an exploit, I just found out while doing a code
review for adding libssh2 in MIR(main inclusion review) process (3) for Ubuntu.
I found another NULL pointer issue and it was already fixed here (4)
Thanks
willco007 commentedon Feb 23, 2023
@dfandrich I also noted offline this seems hypothetical and not possible in the noted code path. That said, it would be good form to add a null check to
_libssh2_get_string.src: check for NULL pointer passed to _libssh2_get_string
src: check for NULL pointer passed to _libssh2_get_string
src: check for NULL pointer passed to _libssh2_get_string