Skip to content

Possible wrong pointer in FREE-call in opensssl.c and pem.c #1802

Closed

Description

@LarsNordin-LNdata

I have done a search for possible problems with FREE and double-free and found this in openssl.c:

    if(application && *application) {
        LIBSSH2_FREE(session, (void *)application);
        *application = NULL;
    }

    if(key_handle && *key_handle) {
        LIBSSH2_FREE(session, (void *)key_handle);
        *key_handle = NULL;
    }

Shouldn't in be *application sent to FREE? as in

          LIBSSH2_FREE(session, (void *)*application);
   
          LIBSSH2_FREE(session, (void *)*key_handle);
    

and this check locks odd:

    *key_handle = LIBSSH2_ALLOC(session, *handle_len);

            if(key_handle) {
                memcpy((void *)LIBSSH2_UNCONST(*key_handle),
                       handle, *handle_len);
            }

should it not be:

 if(*key_handle) {

In pem.c there is:

 /* Initialize the decryption */
 if(method->init(session, method, iv, &free_iv, secret,
                  &free_secret, 0, &abstract)) {
     _libssh2_explicit_zero((char *)secret, sizeof(secret));
     LIBSSH2_FREE(session, data);
     ret = -1;
     goto out;
 }

where the next line is:

/* Do the actual decryption */
if((*datalen % blocksize) != 0) {
    _libssh2_explicit_zero((char *)secret, sizeof(secret));
    method->dtor(session, &abstract);
    _libssh2_explicit_zero(*data, *datalen);
    LIBSSH2_FREE(session, *data);
    ret = -1;
    goto out;
}

I think the first line of code should FREE *data (and also add the explicit_zero)

Activity

  1. changed the title [-]Possible wrong pointer in FREE-call in opensssl.c[/-] [+]Possible wrong pointer in FREE-call in opensssl.c and pem.c[/+] on Feb 13, 2026
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions