To reproduce:
$ (ulimit -f 1 && cp /etc/rc /tmp/rc)
cp: /tmp/rc: No such file or directory
$ (ulimit -f 1 && cp /etc/rc /tmp/rc)
cp: /tmp/rc: Undefined error: 0
$
Patch:
diff -rup /usr/src/bin/cp/utils.c cp/utils.c
--- /usr/src/bin/cp/utils.c Sun Nov 28 20:28:41 2021
+++ cp/utils.c Fri May 6 23:25:01 2022
@@ -149,8 +149,13 @@ copy_file(FTSENT *entp, int exists)
wcount = lseek(to_fd, rcount, SEEK_CUR) == -1 ?
-1 : rcount;
else
wcount = write(to_fd, buf, rcount);
- if (rcount != wcount || wcount == -1) {
+ if (wcount == -1) {
warn("%s", to.p_path);
+ rval = 1;
+ break;
+ }
+ if (rcount != wcount) {
+ warnx("%s: short write", to.p_path);
rval = 1;
break;
}