Commit b260e144 authored by unknown's avatar unknown

Fix for bug #31566: my_write(fd, 0x0, 0, flags) fails with EFAULT on

some platforms

Since the behavior of write(fd, buf, 0) is undefined, it may fail with
EFAULT on some architectures when buf == NULL. The error was propagated
up to a caller, since my_write() code did not handle it properly.

Fixed by checking the 'number of bytes' argument in my_write() and
returning before calling the write() system call when there is nothing
to write.


mysys/my_write.c:
  Return from my_write() before calling the write() system call when the
  number of bytes to be written is 0, since the behavior of write() in
  this case is not portable.
parent 010d3126
...@@ -29,6 +29,10 @@ uint my_write(int Filedes, const byte *Buffer, uint Count, myf MyFlags) ...@@ -29,6 +29,10 @@ uint my_write(int Filedes, const byte *Buffer, uint Count, myf MyFlags)
Filedes, (long) Buffer, Count, MyFlags)); Filedes, (long) Buffer, Count, MyFlags));
errors=0; written=0L; errors=0; written=0L;
/* The behavior of write(fd, buf, 0) is not portable */
if (unlikely(!Count))
return 0;
for (;;) for (;;)
{ {
if ((writenbytes = (uint) write(Filedes, Buffer, Count)) == Count) if ((writenbytes = (uint) write(Filedes, Buffer, Count)) == Count)
......
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