kernel/fs: On write, relax address check on 0 length and NULL ptr

* IEEE Std 1003.1-2017, read, write
* golang performs a write of 0 length with a NULL buffer to
  "create" an empty file. We return BAD_ADDRESS for this.
* If condition above occurs, continue as a length of 0 means
  we won't read the passed buffer.

Change-Id: I8718abb92f5865a7b6f4fb7f2b74f803497ebef0
Reviewed-on: https://review.haiku-os.org/c/haiku/+/3285
Reviewed-by: Alex von Gluck IV <[email protected]>
Reviewed-by: Adrien Destugues <[email protected]>
This commit is contained in:
Alexander von Gluck IV
2020-11-15 20:00:55 +00:00
committed by Adrien Destugues
parent dad52bddc7
commit a756a8ad1b
+6 -3
View File
@@ -731,9 +731,6 @@ common_close(int fd, bool kernel)
static ssize_t
common_user_io(int fd, off_t pos, void* buffer, size_t length, bool write)
{
if (!IS_USER_ADDRESS(buffer))
return B_BAD_ADDRESS;
if (pos < -1)
return B_BAD_VALUE;
@@ -758,6 +755,12 @@ common_user_io(int fd, off_t pos, void* buffer, size_t length, bool write)
return B_BAD_VALUE;
}
if (length == 0)
return 0;
if (!IS_USER_ADDRESS(buffer))
return B_BAD_ADDRESS;
SyscallRestartWrapper<status_t> status;
if (write)