scp of sysfs file repeats data
Peter Korsgaard
peter at korsgaard.com
Tue Jun 23 15:11:35 AWST 2015
>>>>> "Craig" == Craig McQueen <craig.mcqueen at innerrange.com> writes:
> I tried doing scp of a sysfs attribute. I found that it duplicated the
> data, as well as adding extra NUL bytes. E.g.:
> # scp /sys/class/net/eth0/address localhost:
> # cat ~/address
> d0:39:72:53:ef:0e
> d0:39:72:53:ef:0e
> # hexdump -C ~/address
> 00000000 64 30 3a 33 39 3a 37 32 3a 35 33 3a 65 66 3a 30 |d0:39:72:53:ef:0|
> 00000010 65 0a 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |e...............|
> 00000020 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
> *
> 00000800 64 30 3a 33 39 3a 37 32 3a 35 33 3a 65 66 3a 30 |d0:39:72:53:ef:0|
> 00000810 65 0a 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |e...............|
> 00000820 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
> *
> 00001000
> Does that seem normal?
No, that looks like a bug. I see it as well here:
strace output looks like this (for a sysfs property called control).
open("control", O_RDONLY|O_LARGEFILE) = 3
fstat64(3, {st_mode=S_IFREG|0644, st_size=4096, ...}) = 0
write(6, "C0644 4096 control\n", 19) = 19
read(3, "auto\n", 2048) = 5
read(3, "", 2043) = 0
write(6, "auto\n\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 2048) = 2048
read(3, "", 2048) = 0
write(6, "auto\n\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 2048) = 2048
The logic in scp.c always tries to copy st_size bytes, but the sysfs
properties always claim to be 4096 while they in reality are shorter.
I guess the loop in source() needs to be changed to end on error or eof
instead.
--
Bye, Peter Korsgaard
More information about the Dropbear
mailing list