-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Fix UB in test_unistd_write_broken_link #23125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| #include <assert.h> | ||
| #include <errno.h> | ||
| #include <fcntl.h> | ||
| #include <stdio.h> | ||
|
|
@@ -10,21 +11,23 @@ int main() { | |
| printf("link result: %d\n", res); | ||
| int src_fd = open("link_source", O_CREAT | O_WRONLY, 0777); | ||
| printf("source_fd: %d, errno: %d %s\n", src_fd, errno, strerror(errno)); | ||
| write(src_fd, "abc", 3); | ||
| write(src_fd, "abc\0", 4); | ||
| close(src_fd); | ||
| { | ||
| int target_fd = open("link_target", O_RDONLY); | ||
| printf("target_fd: %d, errno: %d %s\n", target_fd, errno, strerror(errno)); | ||
| char buf[10]; | ||
| read(target_fd, buf, 10); | ||
| size_t r = read(target_fd, buf, 10); | ||
| assert(r == 4); | ||
| printf("buf: '%s'\n", buf); | ||
| close(target_fd); | ||
| } | ||
| { | ||
| int target_fd = open("link_source", O_RDONLY); | ||
| printf("target_fd: %d, errno: %d %s\n", target_fd, errno, strerror(errno)); | ||
| char buf[10]; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. An alternative here I suppose would be intialize buf on the stack with
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I could go either way on that, do you have a preference? |
||
| read(target_fd, buf, 10); | ||
| size_t r = read(target_fd, buf, 10); | ||
| assert(r == 4); | ||
| printf("buf: '%s'\n", buf); | ||
| close(target_fd); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems a little odd to write null byte to a text file.. but I guess its not important here.