Skip to content

Commit dc0f623

Browse files
author
Tor Didriksen
committed
Bug#27618273 BUFFER OVERFLOW IN USERVAR,USERNAME,HOSTNAME WITH BROKEN UTF8
The function check_column_name() is used multiple places to verify user input. In order to do a proper job it needs the length of the input string, rather than just a pointer to the first character. Also fix documentation for the validate_string() function. This is a manual backport of commit e12a5db2626bc9104f5536f1876d399e14f847f5 For check_column_name() we backport only the range check when calling my_ismbchar(). In newer branches we also did a validate_string(), but that introduced other/unwanted changes to some test results. Extend suppressions in lsan.supp to work with newer perl versions. Add CTORS taking a LEX_CSTRING for classes Simple_cstring and Name_string. These are taken from commit 46fe1cb52d168bd76bcce11cdb69a6e4ab647f4b Bug#28787272: FIX -WCAST-QUAL COMPILATION WARNINGS [noclose] Change-Id: I70bace14e55c701aec602b058e6ba42c18514cc7
1 parent bcc175a commit dc0f623

File tree

10 files changed

+33
-23
lines changed

10 files changed

+33
-23
lines changed

include/sql_string.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef SQL_STRING_INCLUDED
22
#define SQL_STRING_INCLUDED
33

4-
/* Copyright (c) 2000, 2023, Oracle and/or its affiliates.
4+
/* Copyright (c) 2000, 2025, Oracle and/or its affiliates.
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, version 2.0,
@@ -79,6 +79,8 @@ class Simple_cstring
7979
{
8080
set(arg.str, arg.length);
8181
}
82+
Simple_cstring(const LEX_CSTRING arg) { set(arg.str, arg.length); }
83+
8284
void reset()
8385
{
8486
set(NULL, 0);

mysql-test/lsan.supp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2018, 2023, Oracle and/or its affiliates.
1+
# Copyright (c) 2018, 2025, Oracle and/or its affiliates.
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, version 2.0,
@@ -25,3 +25,9 @@
2525
leak:Perl_safesyscalloc
2626
leak:Perl_safesysmalloc
2727
leak:Perl_safesysrealloc
28+
leak:Perl_savesharedpv
29+
leak:Perl_Slab_Alloc
30+
leak:Perl_newUNOP_AUX
31+
leak:Perl_newSTATEOP
32+
leak:Perl_pmruntime
33+
leak:/lib64/libperl.so.*

sql-common/sql_string.cc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2000, 2023, Oracle and/or its affiliates.
1+
/* Copyright (c) 2000, 2025, Oracle and/or its affiliates.
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, version 2.0,
@@ -1305,8 +1305,7 @@ size_t bin_to_hex_str(char *to, size_t to_len, char *from, size_t from_len)
13051305
prefix for a character, i.e. the byte length
13061306
of that invalid character is undefined.
13071307
1308-
@retval true if the whole input byte sequence is a valid character string.
1309-
The length_error output parameter is undefined.
1308+
@retval true if the input is invalid.
13101309
13111310
@return
13121311
if the whole input byte sequence is a valid character string

sql/item.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef ITEM_INCLUDED
22
#define ITEM_INCLUDED
33

4-
/* Copyright (c) 2000, 2023, Oracle and/or its affiliates.
4+
/* Copyright (c) 2000, 2025, Oracle and/or its affiliates.
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, version 2.0,
@@ -255,6 +255,7 @@ class Name_string: public Simple_cstring
255255
Name_string(const char *str, size_t length):
256256
Simple_cstring(str, length) {}
257257
Name_string(const LEX_STRING str): Simple_cstring(str) {}
258+
Name_string(const LEX_CSTRING str) : Simple_cstring(str) {}
258259
Name_string(const char *str, size_t length, bool is_null_terminated):
259260
Simple_cstring()
260261
{

sql/parse_tree_items.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2013, 2023, Oracle and/or its affiliates.
1+
/* Copyright (c) 2013, 2025, Oracle and/or its affiliates.
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, version 2.0,
@@ -190,7 +190,7 @@ bool PTI_expr_with_alias::itemize(Parse_context *pc, Item **res)
190190
if (alias.str)
191191
{
192192
if (pc->thd->lex->sql_command == SQLCOM_CREATE_VIEW &&
193-
check_column_name(alias.str))
193+
check_column_name(alias))
194194
{
195195
my_error(ER_WRONG_COLUMN_NAME, MYF(0), alias.str);
196196
return true;

sql/sql_class.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2000, 2023, Oracle and/or its affiliates.
1+
/* Copyright (c) 2000, 2025, Oracle and/or its affiliates.
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, version 2.0,
@@ -5507,7 +5507,7 @@ class user_var_entry
55075507
*/
55085508
static user_var_entry *create(THD *thd, const Name_string &name, const CHARSET_INFO *cs)
55095509
{
5510-
if (check_column_name(name.ptr()))
5510+
if (check_column_name(name))
55115511
{
55125512
my_error(ER_ILLEGAL_USER_VAR, MYF(0), name.ptr());
55135513
return NULL;

sql/sql_table.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2000, 2023, Oracle and/or its affiliates.
2+
Copyright (c) 2000, 2025, Oracle and/or its affiliates.
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, version 2.0,
@@ -3731,7 +3731,7 @@ mysql_prepare_create_table(THD *thd, const char *error_schema_name,
37313731
if (!(sql_field->flags & NOT_NULL_FLAG))
37323732
null_fields++;
37333733

3734-
if (check_column_name(sql_field->field_name))
3734+
if (check_column_name(to_lex_cstring(sql_field->field_name)))
37353735
{
37363736
my_error(ER_WRONG_COLUMN_NAME, MYF(0), sql_field->field_name);
37373737
DBUG_RETURN(TRUE);
@@ -4479,7 +4479,7 @@ mysql_prepare_create_table(THD *thd, const char *error_schema_name,
44794479
}
44804480
}
44814481
key_info->actual_flags= key_info->flags;
4482-
if (!key_info->name || check_column_name(key_info->name))
4482+
if (!key_info->name || check_column_name(to_lex_cstring(key_info->name)))
44834483
{
44844484
my_error(ER_WRONG_NAME_FOR_INDEX, MYF(0), key_info->name);
44854485
DBUG_RETURN(TRUE);

sql/sql_view.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2004, 2023, Oracle and/or its affiliates.
1+
/* Copyright (c) 2004, 2025, Oracle and/or its affiliates.
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, version 2.0,
@@ -182,7 +182,7 @@ static void make_valid_column_names(LEX *lex)
182182
for (List_iterator_fast<Item> it(sl->item_list); (item= it++); column_no++)
183183
{
184184
if (!item->item_name.is_autogenerated() ||
185-
!check_column_name(item->item_name.ptr()))
185+
!check_column_name(item->item_name))
186186
continue;
187187
name_len= my_snprintf(buff, NAME_LEN, "Name_exp_%u", column_no);
188188
item->orig_name= item->item_name;

sql/table.cc

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2000, 2023, Oracle and/or its affiliates.
2+
Copyright (c) 2000, 2025, Oracle and/or its affiliates.
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, version 2.0,
@@ -4306,19 +4306,20 @@ enum_ident_name_check check_table_name(const char *name, size_t length,
43064306
}
43074307

43084308

4309-
bool check_column_name(const char *name)
4310-
{
4309+
bool check_column_name(const Name_string &namestring) {
43114310
// name length in symbols
43124311
size_t name_length= 0;
43134312
bool last_char_is_space= TRUE;
4313+
const char *name = namestring.ptr();
4314+
const char *name_end = name + namestring.length();
4315+
const bool is_multibyte = use_mb(system_charset_info);
43144316

43154317
while (*name)
43164318
{
43174319
last_char_is_space= my_isspace(system_charset_info, *name);
4318-
if (use_mb(system_charset_info))
4320+
if (is_multibyte)
43194321
{
4320-
int len=my_ismbchar(system_charset_info, name,
4321-
name+system_charset_info->mbmaxlen);
4322+
int len=my_ismbchar(system_charset_info, name, name_end);
43224323
if (len)
43234324
{
43244325
name += len;

sql/table.h

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

4-
/* Copyright (c) 2000, 2023, Oracle and/or its affiliates.
4+
/* Copyright (c) 2000, 2025, Oracle and/or its affiliates.
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, version 2.0,
@@ -58,6 +58,7 @@ struct LEX;
5858
typedef int8 plan_idx;
5959
class Opt_hints_qb;
6060
class Opt_hints_table;
61+
class Name_string;
6162

6263
#define store_record(A,B) memcpy((A)->B,(A)->record[0],(size_t) (A)->s->reclength)
6364
#define restore_record(A,B) memcpy((A)->record[0],(A)->B,(size_t) (A)->s->reclength)
@@ -2982,7 +2983,7 @@ void open_table_error(TABLE_SHARE *share, int error, int db_errno, int errarg);
29822983
void update_create_info_from_table(HA_CREATE_INFO *info, TABLE *form);
29832984
enum_ident_name_check check_and_convert_db_name(LEX_STRING *db,
29842985
bool preserve_lettercase);
2985-
bool check_column_name(const char *name);
2986+
bool check_column_name(const Name_string &name);
29862987
enum_ident_name_check check_table_name(const char *name, size_t length,
29872988
bool check_for_path_chars);
29882989
int rename_file_ext(const char * from,const char * to,const char * ext);

0 commit comments

Comments
 (0)