FreeBSD Bugzilla – Attachment 247804 Details for
Bug 276045
copy_file_range(2) can truncate the output file when it should not do so
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
Test for this trncation bug
copytest.c (text/plain), 1.33 KB, created by
Rick Macklem
on 2024-01-20 22:01:56 UTC
(
hide
)
Description:
Test for this trncation bug
Filename:
MIME Type:
Creator:
Rick Macklem
Created:
2024-01-20 22:01:56 UTC
Size:
1.33 KB
patch
obsolete
>#include <stdio.h> >#include <stdlib.h> >#include <string.h> >#include <fcntl.h> >#include <errno.h> >#include <sys/param.h> >#include <sys/types.h> >#include <sys/stat.h> >#include <err.h> >#include <unistd.h> > >int >main(int argc, char *argv[]) >{ > int i, infd, outfd; > ssize_t siz, copyret; > char buf[10240]; > struct stat sb; > > if (argc != 3) > errx(1, "Usage: copytest <infile> <outfile>"); > infd = open(argv[1], O_RDWR | O_CREAT | O_TRUNC, 0644); > if (infd < 0) > err(1, "can't open %s", argv[1]); > outfd = open(argv[2], O_RDWR | O_CREAT | O_TRUNC, 0644); > if (outfd < 0) > err(1, "can't open %s", argv[2]); > > /* Write to infd and outfd, making outfd the larger file. */ > for (i = 0; i < 1024; i++) > buf[i] = 'A'; > siz = write(infd, buf, 1024); > if (siz != 1024) > err(1, "Cannot write %s", argv[1]); > for (i = 0; i < 10240; i++) > buf[i] = 'B'; > siz = write(outfd, buf, 10240); > if (siz != 10240) > err(1, "Cannot write %s", argv[2]); > > if (lseek(infd, 0, SEEK_SET) < 0) > err(1, "Cannot lseek %s", argv[1]); > if (lseek(outfd, 0, SEEK_SET) < 0) > err(1, "Cannot lseek %s", argv[2]); > siz = SSIZE_MAX; > /* Now, copy infd to outfd. */ > do { > copyret = copy_file_range(infd, NULL, outfd, NULL, > siz, 0); > } while (copyret > 0); > > if (fstat(outfd, &sb) < 0) > err(1, "Cannot stat %s", argv[2]); > if (sb.st_size != 10240) > errx(1, "File %s size changed", argv[2]); >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 276045
:
247381
|
247804
|
247805