Skip to content

Potential error(e.g., deadlock, ill peformance) due to the server_opts.authkey_lock #320

@jenny-cheung

Description

@jenny-cheung

Hi, developers, thank you for your checking. The lockserver_opts.authkey_lock may not be correctly released if the !server_opts.authkeys satifies. Finally, the method returns with the unreleased lock server_opts.authkey_lock. The fix is to insert pthread_mutex_unlock(&server_opts.authkey_lock); before returning.

pthread_mutex_lock(&server_opts.authkey_lock);

if (!server_opts.authkeys) {

static int
_nc_server_ssh_add_authkey(const char *pubkey_path, const char *pubkey_base64, NC_SSH_KEY_TYPE type, const char *username)
{
    /* LOCK */
    pthread_mutex_lock(&server_opts.authkey_lock); the lock

    ++server_opts.authkey_count;
    server_opts.authkeys = nc_realloc(server_opts.authkeys, server_opts.authkey_count * sizeof *server_opts.authkeys);
    if (!server_opts.authkeys) {
        ERRMEM;
        return -1; //return without releasing lock
    }
    ...;

    /* UNLOCK */
    pthread_mutex_unlock(&server_opts.authkey_lock);

    return 0;
}

Best,

Metadata

Metadata

Assignees

No one assigned

    Labels

    is:bugBug description.status:completedFrom the developer perspective, the issue was solved (bug fixed, question answered,...)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions