1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 21:07:35 +00:00

Kernel: read() and write() should EOVERFLOW if (offset+size) overflows

This commit is contained in:
Andreas Kling 2020-01-12 20:15:53 +01:00
parent 20b2bfcafd
commit 0c44a12247
2 changed files with 25 additions and 0 deletions

View file

@ -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;
}