Skip to content

NULL pointer dereferece issue in _libssh2_get_string() #802

Closed

Description

@nishitm

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.

[1]

rc = _libssh2_get_string(decrypted, &buf, NULL);

[2]
unsigned char *endp = &buf->data[buf->len];

Activity

  1. dfandrich commented on Feb 23, 2023

    @dfandrich
    Contributor
  2. nishitm commented on Feb 23, 2023

    @nishitm
    Author

    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)

    Thanks

  3. willco007 commented on Feb 23, 2023

    @willco007
    Member

    @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.

  4. added a commit that references this issue on Mar 14, 2023
    8b9c640
  5. added a commit that references this issue on Mar 28, 2024
    289b4a1
  6. added a commit that references this issue on Jul 14, 2024
    3d69aa0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions