Skip to content

Commit

Permalink
Bug #23296299 : HANDLE_FATAL_SIGNAL (SIG=11) IN
Browse files Browse the repository at this point in the history
                MY_TOSORT_UTF32

This patch is specific for mysql-5.5

ISSUE: When a charater that is larger than possible to
handle is passed to function my_tosort_utf32(), it results
in segmentation fault. In the scenario mentioned in the bug
AES_ENCRYPT function is used which returns large value.
This value is further passed to my_tosort_utf32 function.
This causes to cross array bound for array uni_plane,
resulting in segment violation.

SOLUTION:
This issue has got addressed in 5.6 onward releases
through worklog 2673.

The fix is similar backport of that.
Check for maximum character before accessing the array
uni_plane. In addition to function my_tosort_utf32, the
same potential problem is also present in functions
my_tolower_utf16, my_toupper_utf16, my_tosort_utf16,
my_tolower_utf32, my_toupper_utf32, my_tosort_unicode,
my_tolower_utf8mb4 and my_toupper_utf8mb4.
Fixed these functions as well.
  • Loading branch information
Kailasnath Nagarkar committed Jul 1, 2016
1 parent 6986645 commit 07a33cd
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions include/m_ctype.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
/* Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -33,11 +33,11 @@ extern "C" {
#define MY_CS_TO_UPPER_TABLE_SIZE 256
#define MY_CS_SORT_ORDER_TABLE_SIZE 256
#define MY_CS_TO_UNI_TABLE_SIZE 256

#define CHARSET_DIR "charsets/"

#define my_wc_t ulong

#define MY_CS_MAX_CHAR 0xFFFF
#define MY_CS_REPLACEMENT_CHARACTER 0xFFFD

/*
Expand Down
14 changes: 7 additions & 7 deletions strings/ctype-ucs2.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
/* Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
Expand Down Expand Up @@ -1099,7 +1099,7 @@ static inline void
my_tolower_utf16(MY_UNICASE_INFO **uni_plane, my_wc_t *wc)
{
int page= *wc >> 8;
if (page < 256 && uni_plane[page])
if (page < 256 && *wc <= MY_CS_MAX_CHAR && uni_plane[page])
*wc= uni_plane[page][*wc & 0xFF].tolower;
}

Expand All @@ -1108,7 +1108,7 @@ static inline void
my_toupper_utf16(MY_UNICASE_INFO **uni_plane, my_wc_t *wc)
{
int page= *wc >> 8;
if (page < 256 && uni_plane[page])
if (page < 256 && *wc <= MY_CS_MAX_CHAR && uni_plane[page])
*wc= uni_plane[page][*wc & 0xFF].toupper;
}

Expand All @@ -1117,7 +1117,7 @@ static inline void
my_tosort_utf16(MY_UNICASE_INFO **uni_plane, my_wc_t *wc)
{
int page= *wc >> 8;
if (page < 256)
if (page < 256 && *wc <= MY_CS_MAX_CHAR)
{
if (uni_plane[page])
*wc= uni_plane[page][*wc & 0xFF].sort;
Expand Down Expand Up @@ -1728,7 +1728,7 @@ static inline void
my_tolower_utf32(MY_UNICASE_INFO **uni_plane, my_wc_t *wc)
{
int page= *wc >> 8;
if (page < 256 && uni_plane[page])
if (page < 256 && *wc <= MY_CS_MAX_CHAR && uni_plane[page])
*wc= uni_plane[page][*wc & 0xFF].tolower;
}

Expand All @@ -1737,7 +1737,7 @@ static inline void
my_toupper_utf32(MY_UNICASE_INFO **uni_plane, my_wc_t *wc)
{
int page= *wc >> 8;
if (page < 256 && uni_plane[page])
if (page < 256 && *wc <= MY_CS_MAX_CHAR && uni_plane[page])
*wc= uni_plane[page][*wc & 0xFF].toupper;
}

Expand All @@ -1746,7 +1746,7 @@ static inline void
my_tosort_utf32(MY_UNICASE_INFO **uni_plane, my_wc_t *wc)
{
int page= *wc >> 8;
if (page < 256)
if (page < 256 && *wc <= MY_CS_MAX_CHAR)
{
if (uni_plane[page])
*wc= uni_plane[page][*wc & 0xFF].sort;
Expand Down
8 changes: 4 additions & 4 deletions strings/ctype-utf8.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
/* Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
Expand Down Expand Up @@ -1941,7 +1941,7 @@ static inline void
my_tosort_unicode(MY_UNICASE_INFO **uni_plane, my_wc_t *wc)
{
int page= *wc >> 8;
if (page < 256)
if (page < 256 && *wc <= MY_CS_MAX_CHAR)
{
if (uni_plane[page])
*wc= uni_plane[page][*wc & 0xFF].sort;
Expand Down Expand Up @@ -5023,7 +5023,7 @@ static inline void
my_tolower_utf8mb4(MY_UNICASE_INFO **uni_plane, my_wc_t *wc)
{
int page= *wc >> 8;
if (page < 256 && uni_plane[page])
if (page < 256 && *wc <= MY_CS_MAX_CHAR && uni_plane[page])
*wc= uni_plane[page][*wc & 0xFF].tolower;
}

Expand All @@ -5032,7 +5032,7 @@ static inline void
my_toupper_utf8mb4(MY_UNICASE_INFO **uni_plane, my_wc_t *wc)
{
int page= *wc >> 8;
if (page < 256 && uni_plane[page])
if (page < 256 && *wc <= MY_CS_MAX_CHAR && uni_plane[page])
*wc= uni_plane[page][*wc & 0xFF].toupper;
}

Expand Down

0 comments on commit 07a33cd

Please sign in to comment.