Commit 1e7ad5bb authored by Marko Mäkelä's avatar Marko Mäkelä

MDEV-15584: Do not invoke open(dir=NULL)

On Linux, <fcntl.h> declares open(2) as having a nonnull first argument.
In GCC 8, if a function with nonnull argument is called, that argument
will be silently assumed to nonnull along the same code path. Hence,
later nullness checks for this argument can be optimized away.

Similar to MDEV-15587, the fix is to ensure that functions with
nonnull arguments are not being called with NULL.

This bug caused a crash in mysqlbinlog, which was invoking
create_temp_file() with the argument dir=NULL. The affected test was
binlog.binlog_mysqlbinlog_base64. It would display the following message
before crashing:

mysqlbinlog: O_TMPFILE is not supported on (null) (disabling future attempts)
Segmentation fault
parent d8303c3e
......@@ -65,7 +65,7 @@ File create_temp_file(char *to, const char *dir, const char *prefix,
File file= -1;
DBUG_ENTER("create_temp_file");
DBUG_PRINT("enter", ("dir: %s, prefix: %s", dir, prefix));
DBUG_PRINT("enter", ("dir: %s, prefix: %s", dir ? dir : "(null)", prefix));
DBUG_ASSERT((mode & (O_EXCL | O_TRUNC | O_CREAT | O_RDWR)) == 0);
mode|= O_TRUNC | O_CREAT | O_RDWR; /* not O_EXCL, see Windows code below */
......@@ -110,6 +110,8 @@ File create_temp_file(char *to, const char *dir, const char *prefix,
}
}
#elif defined(HAVE_MKSTEMP)
if (!dir && ! (dir =getenv("TMPDIR")))
dir= DEFAULT_TMPDIR;
#ifdef O_TMPFILE
{
static int O_TMPFILE_works= 1;
......@@ -146,8 +148,6 @@ File create_temp_file(char *to, const char *dir, const char *prefix,
prefix ? prefix : "tmp.",
sizeof(prefix_buff)-7),"XXXXXX") -
prefix_buff);
if (!dir && ! (dir =getenv("TMPDIR")))
dir= DEFAULT_TMPDIR;
if (strlen(dir)+ pfx_len > FN_REFLEN-2)
{
errno=my_errno= ENAMETOOLONG;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment