Skip to content

Commit 475dcde

Browse files
Bug#27099029: UNLIMITED LENGTH OF THE PASSWORD
Description: my_crypt_genhash depends on the length of plaintext password. Longer the password, more is the time required to produce the transformation. An unusually large password may consume considerable amount of time. Fix: Fixed length of plaintext password to 256 bytes for SHA256_PASSWORD authentication plugin. Restricted PASSWORD() to accept at max 256 bytes if old_passwords is set to 2.
1 parent 88301e5 commit 475dcde

File tree

3 files changed

+40
-3
lines changed

3 files changed

+40
-3
lines changed

include/crypt_genhash_impl.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/* Copyright (c) 2012, 2017, Oracle and/or its affiliates. All rights reserved.
2+
3+
This program is free software; you can redistribute it and/or modify
4+
it under the terms of the GNU General Public License as published by
5+
the Free Software Foundation; version 2 of the License.
6+
7+
This program is distributed in the hope that it will be useful,
8+
but WITHOUT ANY WARRANTY; without even the implied warranty of
9+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10+
GNU General Public License for more details.
11+
12+
You should have received a copy of the GNU General Public License
13+
along with this program; if not, write to the Free Software
14+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
15+
116
#ifndef CRYPT_HASHGEN_IMPL_H
217
#define CRYPT_HASHGEN_IMPL_H
318
#define ROUNDS_DEFAULT 5000
@@ -13,6 +28,8 @@
1328
CRYPT_MAGIC_LENGTH + \
1429
CRYPT_PARAM_LENGTH)
1530

31+
#define MAX_PLAINTEXT_LENGTH 256
32+
1633
#include <stddef.h>
1734
#include <my_global.h>
1835

sql/item_strfunc.cc

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2192,6 +2192,11 @@ static int calculate_password(String *str, char *buffer)
21922192
#if defined(HAVE_OPENSSL)
21932193
if (old_passwords == 2)
21942194
{
2195+
if (str->length() > MAX_PLAINTEXT_LENGTH)
2196+
{
2197+
my_error(ER_NOT_VALID_PASSWORD, MYF(0));
2198+
return 0;
2199+
}
21952200
my_make_scrambled_password(buffer, str->ptr(),
21962201
str->length());
21972202
buffer_len= (int) strlen(buffer) + 1;
@@ -2283,9 +2288,14 @@ char *Item_func_password::
22832288
#if defined(HAVE_OPENSSL)
22842289
else
22852290
{
2286-
/* Allocate memory for the password scramble and one extra byte for \0 */
2287-
buff= (char *) thd->alloc(CRYPT_MAX_PASSWORD_SIZE + 1);
2288-
my_make_scrambled_password(buff, password, pass_len);
2291+
if (pass_len <= MAX_PLAINTEXT_LENGTH)
2292+
{
2293+
/* Allocate memory for the password scramble and one extra byte for \0 */
2294+
buff= (char *) thd->alloc(CRYPT_MAX_PASSWORD_SIZE + 1);
2295+
my_make_scrambled_password(buff, password, pass_len);
2296+
}
2297+
else
2298+
my_error(ER_NOT_VALID_PASSWORD, MYF(0));
22892299
}
22902300
#endif
22912301
return buff;

sql/sql_acl.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@
6666
"$5$BVZy9O>'a+2MH]_?$fpWyabcdiHjfCVqId/quykZzjaA7adpkcen/uiQrtmOK4p4"
6767
#endif
6868

69+
#if defined(HAVE_OPENSSL)
70+
#define SHA256_PASSWORD_MAX_PASSWORD_LENGTH MAX_PLAINTEXT_LENGTH
71+
#endif /* HAVE_OPENSSL */
72+
6973
using std::min;
7074
using std::max;
7175

@@ -5462,6 +5466,9 @@ int digest_password(THD *thd, LEX_USER *user_record)
54625466
*/
54635467
if (user_record->plugin.str == sha256_password_plugin_name.str)
54645468
{
5469+
if (user_record->password.length > SHA256_PASSWORD_MAX_PASSWORD_LENGTH)
5470+
return 1;
5471+
54655472
char *buff= (char *) thd->alloc(CRYPT_MAX_PASSWORD_SIZE+1);
54665473
if (buff == NULL)
54675474
return 1;
@@ -12621,6 +12628,9 @@ static int sha256_password_authenticate(MYSQL_PLUGIN_VIO *vio,
1262112628
#endif
1262212629
} // if(!my_vio_is_encrypter())
1262312630

12631+
if (pkt_len > SHA256_PASSWORD_MAX_PASSWORD_LENGTH + 1)
12632+
DBUG_RETURN(CR_ERROR);
12633+
1262412634
/* A password was sent to an account without a password */
1262512635
if (info->auth_string_length == 0)
1262612636
DBUG_RETURN(CR_ERROR);

0 commit comments

Comments
 (0)