Commit 78aa6599 authored by kaa@polly.(none)'s avatar kaa@polly.(none)
Browse files

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.
parent 48ada204
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -29,6 +29,10 @@ uint my_write(int Filedes, const byte *Buffer, uint Count, myf MyFlags)
		   Filedes, (long) Buffer, Count, MyFlags));
  errors=0; written=0L;

  /* The behavior of write(fd, buf, 0) is not portable */
  if (unlikely(!Count))
    return 0;
  
  for (;;)
  {
    if ((writenbytes = (uint) write(Filedes, Buffer, Count)) == Count)