summaryrefslogtreecommitdiff
path: root/mysys
diff options
context:
space:
mode:
authorkaa@polly.(none) <>2007-10-24 21:16:20 +0400
committerkaa@polly.(none) <>2007-10-24 21:16:20 +0400
commit78aa659979b02afeb26ec51742559e516a2ba41e (patch)
tree80dc736a39f64681fa4f9bb7dda246dc2b601ce8 /mysys
parent48ada204d134c13a2836a9b417c6f289c04dd917 (diff)
downloadmariadb-git-78aa659979b02afeb26ec51742559e516a2ba41e.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.
Diffstat (limited to 'mysys')
-rw-r--r--mysys/my_write.c4
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)