Skip to content

Commit 6a396fd

Browse files
author
Mats Kindahl
committed
Bug #58455
Starting mysqld with defaults file without extension cause segmentation fault Bug occurs because fn_expand calls fn_format with NULL as ext. This is a backport of the patch from 5.6. Patch solve this problem by using an empty string as extension, and adding assertions to fn_format that correct arguments are passed. It also add a test tests several variations of using non-existing defaults files.
1 parent ef2eb87 commit 6a396fd

File tree

4 files changed

+62
-1
lines changed

4 files changed

+62
-1
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Could not open required defaults file: /path/with/no/extension
2+
Fatal error in defaults handling. Program aborted
3+
Could not open required defaults file: /path/with.ext
4+
Fatal error in defaults handling. Program aborted
5+
Could not open required defaults file: MYSQL_TEST_DIR/relative/path/with.ext
6+
Fatal error in defaults handling. Program aborted
7+
Could not open required defaults file: MYSQL_TEST_DIR/relative/path/without/extension
8+
Fatal error in defaults handling. Program aborted
9+
Could not open required defaults file: MYSQL_TEST_DIR/with.ext
10+
Fatal error in defaults handling. Program aborted
11+
Could not open required defaults file: MYSQL_TEST_DIR/no_extension
12+
Fatal error in defaults handling. Program aborted
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# BUG#58455
2+
# Starting mysqld with defaults file without extension cause
3+
# segmentation fault
4+
5+
source include/not_embedded.inc;
6+
source include/not_windows.inc;
7+
8+
# We need to use a plain "mysqld" without any other options to trigger
9+
# the bug. In particular, it seems that passing --bootstrap does not
10+
# trigger the bug. To do that, we extract the "command name" from the
11+
# MYSQLD_BOOTSTRAP_CMD variable and store that in a file, which we
12+
# then load into the test case.
13+
14+
perl;
15+
my ($mysqld)= split " ", $ENV{MYSQLD_BOOTSTRAP_CMD};
16+
open(FILE, ">", "$ENV{MYSQL_TMP_DIR}/mysqld.inc") or die;
17+
print FILE "let \$MYSQLD= $mysqld;\n";
18+
close FILE;
19+
EOF
20+
21+
source $MYSQL_TMP_DIR/mysqld.inc;
22+
23+
# All these tests refer to configuration files that do not exist
24+
25+
--error 1
26+
exec $MYSQLD --defaults-file=/path/with/no/extension --print-defaults 2>&1;
27+
28+
--error 1
29+
exec $MYSQLD --defaults-file=/path/with.ext --print-defaults 2>&1;
30+
31+
--replace_result $MYSQL_TEST_DIR MYSQL_TEST_DIR
32+
--error 1
33+
exec $MYSQLD --defaults-file=relative/path/with.ext --print-defaults 2>&1;
34+
35+
--replace_result $MYSQL_TEST_DIR MYSQL_TEST_DIR
36+
--error 1
37+
exec $MYSQLD --defaults-file=relative/path/without/extension --print-defaults 2>&1;
38+
39+
--replace_result $MYSQL_TEST_DIR MYSQL_TEST_DIR
40+
--error 1
41+
exec $MYSQLD --defaults-file=with.ext --print-defaults 2>&1;
42+
43+
--replace_result $MYSQL_TEST_DIR MYSQL_TEST_DIR
44+
--error 1
45+
exec $MYSQLD --defaults-file=no_extension --print-defaults 2>&1;
46+
47+
remove_file $MYSQL_TMP_DIR/mysqld.inc;

mysys/default.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ fn_expand(const char *filename, char *result_buf)
179179
if (my_getwd(dir, sizeof(dir), MYF(0)))
180180
DBUG_RETURN(3);
181181
DBUG_PRINT("debug", ("dir: %s", dir));
182-
if (fn_format(result_buf, filename, dir, NULL, flags) == NULL)
182+
if (fn_format(result_buf, filename, dir, "", flags) == NULL)
183183
DBUG_RETURN(2);
184184
DBUG_PRINT("return", ("result: %s", result_buf));
185185
DBUG_RETURN(0);

mysys/mf_format.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ char * fn_format(char * to, const char *name, const char *dir,
3131
reg1 size_t length;
3232
size_t dev_length;
3333
DBUG_ENTER("fn_format");
34+
DBUG_ASSERT(name != NULL);
35+
DBUG_ASSERT(extension != NULL);
3436
DBUG_PRINT("enter",("name: %s dir: %s extension: %s flag: %d",
3537
name,dir,extension,flag));
3638

0 commit comments

Comments
 (0)