Skip to content

Commit a7c71c5

Browse files
Merge branch 'mysql-5.6' into mysql-5.7
2 parents 4b4dd7a + 475dcde commit a7c71c5

File tree

4 files changed

+18
-31
lines changed

4 files changed

+18
-31
lines changed

include/crypt_genhash_impl.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved.
1+
/* Copyright (c) 2012, 2017, Oracle and/or its affiliates. All rights reserved.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License as published by
@@ -28,6 +28,8 @@
2828
CRYPT_MAGIC_LENGTH + \
2929
CRYPT_PARAM_LENGTH)
3030

31+
#define MAX_PLAINTEXT_LENGTH 256
32+
3133
#include <stddef.h>
3234
#include <my_global.h>
3335

sql/auth/sql_authentication.cc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ my_bool disconnect_on_expired_password= TRUE;
8181

8282
#if defined(HAVE_OPENSSL)
8383
#define MAX_CIPHER_LENGTH 1024
84+
#define SHA256_PASSWORD_MAX_PASSWORD_LENGTH MAX_PLAINTEXT_LENGTH
8485
#if !defined(HAVE_YASSL)
8586
#define AUTH_DEFAULT_RSA_PRIVATE_KEY "private_key.pem"
8687
#define AUTH_DEFAULT_RSA_PUBLIC_KEY "public_key.pem"
@@ -2640,7 +2641,8 @@ int set_native_salt(const char* password, unsigned int password_len,
26402641
int generate_sha256_password(char *outbuf, unsigned int *buflen,
26412642
const char *inbuf, unsigned int inbuflen)
26422643
{
2643-
if (my_validate_password_policy(inbuf, inbuflen))
2644+
if (inbuflen > SHA256_PASSWORD_MAX_PASSWORD_LENGTH ||
2645+
my_validate_password_policy(inbuf, inbuflen))
26442646
return 1;
26452647
if (inbuflen == 0)
26462648
{
@@ -3040,6 +3042,10 @@ static int sha256_password_authenticate(MYSQL_PLUGIN_VIO *vio,
30403042
#endif /* HAVE_YASSL */
30413043
} // if(!my_vio_is_encrypter())
30423044

3045+
/* Don't process the password if it is longer than maximum limit */
3046+
if (pkt_len > SHA256_PASSWORD_MAX_PASSWORD_LENGTH + 1)
3047+
DBUG_RETURN(CR_ERROR);
3048+
30433049
/* A password was sent to an account without a password */
30443050
if (info->auth_string_length == 0)
30453051
DBUG_RETURN(CR_ERROR);

sql/item_strfunc.cc

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
2+
Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
33
44
This program is free software; you can redistribute it and/or modify
55
it under the terms of the GNU General Public License as published by
@@ -2159,6 +2159,12 @@ static size_t calculate_password(String *str, char *buffer)
21592159
#if defined(HAVE_OPENSSL)
21602160
if (old_passwords == 2)
21612161
{
2162+
if (str->length() > MAX_PLAINTEXT_LENGTH)
2163+
{
2164+
my_error(ER_NOT_VALID_PASSWORD, MYF(0));
2165+
return 0;
2166+
}
2167+
21622168
my_make_scrambled_password(buffer, str->ptr(),
21632169
str->length());
21642170
buffer_len= strlen(buffer) + 1;
@@ -2226,31 +2232,6 @@ String *Item_func_password::val_str_ascii(String *str)
22262232
return str;
22272233
}
22282234

2229-
char *Item_func_password::
2230-
create_password_hash_buffer(THD *thd, const char *password, size_t pass_len)
2231-
{
2232-
String *password_str= new (thd->mem_root)String(password, thd->variables.
2233-
character_set_client);
2234-
my_validate_password_policy(password_str->ptr(), password_str->length());
2235-
2236-
char *buff= NULL;
2237-
if (thd->variables.old_passwords == 0)
2238-
{
2239-
/* Allocate memory for the password scramble and one extra byte for \0 */
2240-
buff= (char *) thd->alloc(SCRAMBLED_PASSWORD_CHAR_LENGTH + 1);
2241-
my_make_scrambled_password_sha1(buff, password, pass_len);
2242-
}
2243-
#if defined(HAVE_OPENSSL)
2244-
else
2245-
{
2246-
/* Allocate memory for the password scramble and one extra byte for \0 */
2247-
buff= (char *) thd->alloc(CRYPT_MAX_PASSWORD_SIZE + 1);
2248-
my_make_scrambled_password(buff, password, pass_len);
2249-
}
2250-
#endif
2251-
return buff;
2252-
}
2253-
22542235
bool Item_func_encrypt::itemize(Parse_context *pc, Item **res)
22552236
{
22562237
if (skip_itemize(res))

sql/item_strfunc.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef ITEM_STRFUNC_INCLUDED
22
#define ITEM_STRFUNC_INCLUDED
33

4-
/* Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
4+
/* Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
55
66
This program is free software; you can redistribute it and/or modify
77
it under the terms of the GNU General Public License as published by
@@ -485,8 +485,6 @@ class Item_func_password :public Item_str_ascii_func
485485
String *val_str_ascii(String *str);
486486
void fix_length_and_dec();
487487
const char *func_name() const { return "password"; }
488-
static char *create_password_hash_buffer(THD *thd, const char *password,
489-
size_t pass_len);
490488
};
491489

492490

0 commit comments

Comments
 (0)