@jfinkels I took the liberty to open a new issue with a summary for all the findings you published in #3447
gnu/tests/dd/skip-seek-past-dev.sh runs
device=$(df --output=source . | tail -n1)
dev_size=$(blockdev --getsize64 $device)
DEV_OFLOW=$(expr $dev_size + 1)
dd bs=1 seek=$DEV_OFLOW count=0 status=noxfer > "$device"
and expects $?=1 and stderr=dd: 'standard output': cannot seek: Invalid argument.
However, uu_tail does not check if stdout is a redirect to a seekable device and then writes null bytes to $device !
|
let mut dst = io::stdout(); |
|
|
|
// The --seek and --oseek flags are additive. |
|
let amt = seek.unwrap_or(0) + oseek.unwrap_or(0); |
|
// stdout is not seekable, so we just write null bytes. |
|
if amt > 0 { |
|
io::copy(&mut io::repeat(0u8).take(amt as u64), &mut dst) |
|
.map_err_context(|| String::from("write error"))?; |
|
} |
possible fix
Haven't looked into it much but a possible fix could be to get the redirect for /dev/stdout similar to this:
|
if let Ok(p) = Path::new("/dev/stdin").canonicalize() { |
|
p.into_os_string() |
|
} else { |
|
OsString::from("/dev/stdin") |
|
} |
and then apply the seek checks for the new path.
@jfinkels I took the liberty to open a new issue with a summary for all the findings you published in #3447
gnu/tests/dd/skip-seek-past-dev.shrunsand expects
$?=1 and stderr=dd: 'standard output': cannot seek: Invalid argument.However, uu_tail does not check if
stdoutis a redirect to a seekable device and then writes null bytes to$device!coreutils/src/uu/dd/src/dd.rs
Lines 301 to 309 in d894847
possible fix
Haven't looked into it much but a possible fix could be to get the redirect for
/dev/stdoutsimilar to this:coreutils/src/uu/stat/src/stat.rs
Lines 558 to 562 in d894847
and then apply the seek checks for the new path.