NetBSD-Bugs archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
bin/56443: dd conv=swab doesn't always work
>Number: 56443
>Category: bin
>Synopsis: dd conv=swab doesn't always work
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: bin-bug-people
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Wed Oct 06 07:35:00 +0000 2021
>Originator: RVP
>Release: NetBSD/amd64 9.99.90
>Organization:
>Environment:
NetBSD x202e.localdomain 9.99.90 NetBSD 9.99.90 (MYKERNEL) #0: Wed Oct 6 03:29:01 UTC 2021 bld@x202e.localdomain:/usr/obj/sys/arch/amd64/compile/MYKERNEL amd64
>Description:
dd conv=swab doesn't swap the final pair of bytes at the end of input or
of the buffer:
$ printf 'abcdefgh' | dd conv=swab msgfmt=quiet
badcfegh
$ printf 'abcdefgh' | dd conv=swab msgfmt=quiet bs=4
bacdfegh
$
>How-To-Repeat:
See above, and also run this test script:
---START dd_test.sh---
#!/bin/sh
set -eu -o pipefail
opt="conv=swab msgfmt=quiet"
# make a ~1K buffer
data=$(jot -b abcdefghijklmnopqrstuvwxyz 40 | tr -d '\n')
for n in $(jot 521) # a prime no. > def. block size
do in=$(printf '%.*s' $n "$data" | ./swab)
out=$(printf '%.*s' $n "$data" | dd $opt)
if [ "$in" != "$out" ]
then echo >&2 "$0: mismatch @ len $n:"
echo >&2 "exp: $in"
echo >&2 "got: $out"
exit 1
fi
done
---END dd_test.sh---
which needs this program to be compiled:
---START swab.c---
/**
* swap byte-pairs
*/
#include <stdio.h>
int
main(void)
{
int c1, c2;
for (;;) {
if ((c1 = getchar()) == EOF)
break;
if ((c2 = getchar()) == EOF) {
printf("%c", c1);
break;
}
printf("%c%c", c2, c1);
}
return 0;
}
---END swab.c---
>Fix:
diff -urN dd.orig/dd_swab.c dd/dd_swab.c
--- dd.orig/dd_swab.c 2019-10-04 08:57:38.000000000 +0000
+++ dd/dd_swab.c 2021-09-18 09:18:12.127706233 +0000
@@ -71,7 +71,7 @@
}
/* round to multiple of 8 */
- while ((--len % 8) != 0)
+ for ( ;(len % 8) != 0; --len)
STEP;
len /= 8;
if (len == 0)
Home |
Main Index |
Thread Index |
Old Index