Skip to content

Commit 1f1cba1

Browse files
committed
better error handling when source command targets a directory
1 parent eb5712b commit 1f1cba1

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

client/mysql.cc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4531,6 +4531,7 @@ static int com_source(String *, char *line)
45314531
STATUS old_status;
45324532
FILE *sql_file;
45334533
my_bool save_ignore_errors;
4534+
MY_STAT stat_info;
45344535

45354536
if (status.sandbox)
45364537
return put_info("Not allowed in the sandbox mode", INFO_ERROR, 0);
@@ -4557,6 +4558,16 @@ static int com_source(String *, char *line)
45574558
return put_info(buff, INFO_ERROR, 0);
45584559
}
45594560

4561+
/* verify it's not a directory */
4562+
if (my_fstat(fileno(sql_file), &stat_info, MYF(0)) == 0 &&
4563+
MY_S_ISDIR(stat_info.st_mode))
4564+
{
4565+
my_fclose(sql_file, MYF(0));
4566+
char buff[FN_REFLEN+60];
4567+
sprintf(buff, "'%s' is a directory, not a file", source_name);
4568+
return put_info(buff, INFO_ERROR, 0);
4569+
}
4570+
45604571
if (!(line_buff= batch_readline_init(MAX_BATCH_BUFFER_SIZE, sql_file)))
45614572
{
45624573
my_fclose(sql_file,MYF(0));

0 commit comments

Comments
 (0)