Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mysql close connection after return #230

Open
baimard opened this issue Jul 23, 2021 · 1 comment
Open

Mysql close connection after return #230

baimard opened this issue Jul 23, 2021 · 1 comment

Comments

@baimard
Copy link
Contributor

baimard commented Jul 23, 2021

in util.c

  while(!mysql_stmt_fetch(stmt))
  {
    if(bind[0].is_null_value)
    {
      D (debug_file, "mysql_stmt_fetch() failed");
    }
    else
    {
      if(otp_id != NULL){
        if(int_data)
        {
          return AUTH_FOUND;
        }
        else
        {
          return AUTH_NOT_FOUND;
        }
      }
      else if(otp_id == NULL)
      {
        if(int_data)
        {
          return AUTH_NOT_FOUND;
        }
        else
        {
          return AUTH_NO_TOKENS;
        }
      }
    }
  }

  if(mysql_stmt_close(stmt))
  {
    if(verbose)
    D (debug_file, "mysql_stmt_close() failed %s", mysql_stmt_error(stmt));
    return retval;
  }

  mysql_close(con);
  mysql_library_end();

Close connection is after the return.

In production mode with lot of users, that can cause too many connection quickly on the database.

I will propose a fix in a pull request.

hot fix would be :

  if(mysql_stmt_close(stmt))
  {
    if(verbose)
    D (debug_file, "mysql_stmt_close() failed %s", mysql_stmt_error(stmt));
    return retval;
  }

  mysql_close(con);
  mysql_library_end();

  while(!mysql_stmt_fetch(stmt))
  {
    if(bind[0].is_null_value)
    {
      D (debug_file, "mysql_stmt_fetch() failed");
    }
    else
    {
      if(otp_id != NULL){
        if(int_data)
        {
          return AUTH_FOUND;
        }
        else
        {
          return AUTH_NOT_FOUND;
        }
      }
      else if(otp_id == NULL)
      {
        if(int_data)
        {
          return AUTH_NOT_FOUND;
        }
        else
        {
          return AUTH_NO_TOKENS;
        }
      }
    }
  }

But in case of errors before this, that can cause a security issue (DDOS).

baimard added a commit to baimard/yubico-pam that referenced this issue Jul 28, 2021
baimard added a commit to baimard/yubico-pam that referenced this issue Jul 28, 2021
baimard added a commit to baimard/yubico-pam that referenced this issue Jul 28, 2021
baimard added a commit to baimard/yubico-pam that referenced this issue Jul 28, 2021
baimard added a commit to baimard/yubico-pam that referenced this issue Jul 28, 2021
baimard added a commit to baimard/yubico-pam that referenced this issue Jul 28, 2021
@baimard
Copy link
Contributor Author

baimard commented Jul 28, 2021

Pull request : #231

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant