summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2020-01-12 20:15:53 +0100
committerAndreas Kling <awesomekling@gmail.com>2020-01-12 20:20:17 +0100
commit0c44a12247352fc6f45c894da433a9688d67965b (patch)
tree12d8d46cb1f04e3bfddead6a6dbd46a25feea1a2 /Userland
parent20b2bfcafdc169d01fb92f71c708e6ae3cf222a8 (diff)
downloadserenity-0c44a12247352fc6f45c894da433a9688d67965b.zip
Kernel: read() and write() should EOVERFLOW if (offset+size) overflows
Diffstat (limited to 'Userland')
-rw-r--r--Userland/test_io.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/Userland/test_io.cpp b/Userland/test_io.cpp
index 2d2982f626..b34a7e762d 100644
--- a/Userland/test_io.cpp
+++ b/Userland/test_io.cpp
@@ -188,6 +188,26 @@ void test_unlink_symlink()
}
}
+void test_eoverflow()
+{
+ int fd = open("/tmp/x", O_RDWR);
+ ASSERT(fd >= 0);
+
+ int rc = lseek(fd, INT32_MAX, SEEK_SET);
+ ASSERT(rc == INT32_MAX);
+
+ char buffer[16];
+ rc = read(fd, buffer, sizeof(buffer));
+ if (rc >= 0 || errno != EOVERFLOW) {
+ fprintf(stderr, "Expected EOVERFLOW when trying to read past INT32_MAX\n");
+ }
+ rc = write(fd, buffer, sizeof(buffer));
+ if (rc >= 0 || errno != EOVERFLOW) {
+ fprintf(stderr, "Expected EOVERFLOW when trying to write past INT32_MAX\n");
+ }
+ close(fd);
+}
+
int main(int, char**)
{
int rc;
@@ -211,6 +231,7 @@ int main(int, char**)
test_procfs_read_past_end();
test_open_create_device();
test_unlink_symlink();
+ test_eoverflow();
return 0;
}