Skip to content

Commit f8fe17e

Browse files
MDEV-35717: UBSAN: runtime errors: applying [zero|non-zero] offset to null pointer
Problem: UBSAN reports runtime errors in string comparision functions where pointer arithmetic is done without checking NULL. Fix: Check pointers are not NULL before doing pointer arithmetic.
1 parent e47db94 commit f8fe17e

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

mysql-test/main/t.result

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#
2+
# MDEV-35717: UBSAN: runtime errors: applying zero offset to null pointer in `my_strnncoll_utf8mb3_general1400_as_ci`, and applying non-zero offset 4 to null pointer in `my_strcoll_ascii_4bytes_found`
3+
#
4+
CREATE TABLE t (c INT,c2 CHAR,c3 DATE,CHECK (c>0));
5+
ALTER TABLE t ADD INDEX (c2) USING HASH;
6+
DROP TABLE t;
7+
# End of 11.8 tests

mysql-test/main/t.test

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
--echo #
2+
--echo # MDEV-35717: UBSAN: runtime errors: applying zero offset to null pointer in `my_strnncoll_utf8mb3_general1400_as_ci`, and applying non-zero offset 4 to null pointer in `my_strcoll_ascii_4bytes_found`
3+
--echo #
4+
5+
CREATE TABLE t (c INT,c2 CHAR,c3 DATE,CHECK (c>0));
6+
ALTER TABLE t ADD INDEX (c2) USING HASH;
7+
8+
DROP TABLE t;
9+
10+
--echo # End of 11.8 tests

strings/strcoll.inl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,8 @@ MY_FUNCTION_NAME(strnncoll)(CHARSET_INFO *cs __attribute__((unused)),
226226
const uchar *b, size_t b_length,
227227
my_bool b_is_prefix)
228228
{
229-
const uchar *a_end= a + a_length;
230-
const uchar *b_end= b + b_length;
229+
const uchar *a_end= a ? a + a_length : NULL;
230+
const uchar *b_end= b ? b + b_length : NULL;
231231
for ( ; ; )
232232
{
233233
int a_weight, b_weight, res;

0 commit comments

Comments
 (0)