diff options
author | unknown <kaa@polly.(none)> | 2007-10-24 21:16:20 +0400 |
---|---|---|
committer | unknown <kaa@polly.(none)> | 2007-10-24 21:16:20 +0400 |
commit | b260e144a591706141b48e49fd1b6a5c302a20f0 (patch) | |
tree | 80dc736a39f64681fa4f9bb7dda246dc2b601ce8 /mysys | |
parent | 010d3126508116cb39ecda6261e15b9f0a5d0d74 (diff) | |
download | mariadb-git-b260e144a591706141b48e49fd1b6a5c302a20f0.tar.gz |
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.
Diffstat (limited to 'mysys')
-rw-r--r-- | mysys/my_write.c | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/mysys/my_write.c b/mysys/my_write.c index 4c3d187e4e8..08d70accd57 100644 --- a/mysys/my_write.c +++ b/mysys/my_write.c @@ -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) |