commit fb16e7c6ad0e8d27cba8ee6279f71f88c7f95fd7
parent 00995639fe3b885494d7dfeda7af618ba018fdd1
Author: Michael Forney <mforney@mforney.org>
Date: Wed, 12 Apr 2023 20:13:51 -0700
dd: Consider block count in inner read loop
When ibs is smaller than obs, checking the block count in the outer
loop is not sufficient; we need to break out of the inner read loop
once we've read the specified number of blocks.
Thanks to phoebos for reporting this issue.
Diffstat:
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/dd.c b/dd.c
@@ -173,8 +173,12 @@ main(int argc, char *argv[])
eprintf("lseek:");
/* XXX: handle non-seekable files */
}
- while (!eof && (count == -1 || ifull + ipart < count)) {
+ while (!eof) {
while (ipos - opos < obs) {
+ if (ifull + ipart == count) {
+ eof = 1;
+ break;
+ }
ret = read(ifd, buf + ipos, ibs);
if (ret == 0) {
eof = 1;