coreutils icon indicating copy to clipboard operation
coreutils copied to clipboard

dd: writes null bytes to device if stdout is redirect to device

Open jhscheer opened this issue 3 years ago • 1 comments
trafficstars

@jfinkels I took the liberty to open a new issue with a summary for all the findings you published in https://github.com/uutils/coreutils/issues/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 ! https://github.com/uutils/coreutils/blob/d894847fc69bcc2e9901b72de689a84cf24837dc/src/uu/dd/src/dd.rs#L301-L309

possible fix

Haven't looked into it much but a possible fix could be to get the redirect for /dev/stdout similar to this: https://github.com/uutils/coreutils/blob/d894847fc69bcc2e9901b72de689a84cf24837dc/src/uu/stat/src/stat.rs#L558-L562 and then apply the seek checks for the new path.

jhscheer avatar May 18 '22 13:05 jhscheer

Thank you for creating a new issue :+1:

jfinkels avatar May 18 '22 22:05 jfinkels