Page MenuHome GnuPG

Test mds.test fails if /bin/sh -> dash
Closed, ResolvedPublic

Description

I run a Gentoo system with kernel 4.4.8, glibc-2.22, dash-0.5.8.2 and bash-4.3_p42

I have a test failure if /bin/sh is symlinked to /bin/dash:

Hash algorithm MD5 is not installed (not an error)
mds.test: :2: :3: :11: :8: :9: :10: failed for a..z
FAIL: mds.test

[...]

1 of 34 tests failed

Please report to http://bugs.gnupg.org

cat mds.test.log

Test: mds.test
GNUPGHOME=/var/tmp/portage/app-crypt/gnupg-2.1.11-r1/work/gnupg-2.1.11/tests/openpgp
mds.test: :2: :3: :11: :8: :9: :10: failed for a..z

Using /bin/bash as /bin/sh all tests succeed.

I've dug around the issue a bit and, IMHO, the culprit is the echo_n function in
tests/openpgp/defs.inc.

In dash, the echo builtin does not support any argument or backslash sequence, thus the function
defines echo_n_n as the empty string and echo_n_c as '
' (which I don't really undestand...).

Then in mds.test is used in line 66 to do:
echo_n "abcdefghijklmnopqrstuvwxyz" | $GPG --with-colons --print-mds >y
which is supposed to get the checksums of the raw "abc....xyz" strings without newlines or anything
else, but this fails with dash because the strings becomes "abc...xyz
" and the checksums are all wrong.

Substituting "echo_n" with "printf" in mds.test fixes this test but I don't know if it may yield other
problems.

Details

Version
2.1.11

Event Timeline

PPed72 set Version to 2.1.11.
PPed72 added a subscriber: PPed72.

I've made the following script to isolate the issue:
#!/bin/sh
echo_n_init=no
echo_n () {

if test "$echo_n_init" = "no"; then
  if (echo "testing\c"; echo 1,2,3) | grep c >/dev/null; then
    if (echo -n testing; echo 1,2,3) | sed s/-n/xn/ | grep xn >/dev/null; then
      echo_n_n=
      echo_n_c='

'

    else
      echo_n_n='-n'
      echo_n_c=
    fi
  else
    echo_n_n=
    echo_n_c='\c'
  fi
  echo_n_init=yes
fi
echo $echo_n_n "${1}$echo_n_c"

}

echo_n "abcdefghijklmnopqrstuvwxyz" | gpg2 --with-colons --print-mds

If I run it with "bash -x" I get:
+ echo_n_init=no
+ echo_n abcdefghijklmnopqrstuvwxyz
+ test no = no
+ echo 'testing\c'
+ echo 1,2,3
+ gpg2 --with-colons --print-mds
+ grep c
+ echo -n testing
+ sed s/-n/xn/
+ echo 1,2,3
+ grep xn
+ echo_n_n=-n
+ echo_n_c=
+ echo_n_init=yes
+ echo -n abcdefghijklmnopqrstuvwxyz
:1:C3FCD3D76192E4007DFB496CCA67E13B:
:2:32D10C7B8CF96570CA04CE37F2A19D84240D3A89:
:3:F71C27109C692C1B56BBDCEB5B9D2865B3708DBC:
:11:45A5F72C39C5CFF2522EB3429799E49E5F44B356EF926BCF390DCCC2:
:8:71C480DF93D6AE2F1EFAD1447C66C9525E316218CF51FC8D9ED832F2DAF18B73:
:9:FEB67349DF3DB6F5924815D6C3DC133F091809213731FE5C7B5F4999E463479FF2877F5F2936FA63BB43784B12F3EBB4:
:10:4DBFF86CC2CA1BAE1E16468A05CB9881C97F1753BCE3619034898FAA1AABE429955A1BF8EC483D7421FE3C1646613A59ED5441F
B0F321389F77F48A879C7B1F1:

which is correct. If I run it with "dash -x" I get:
+ echo_n_init=no
+ echo_n abcdefghijklmnopqrstuvwxyz
+ test no =+ no
gpg2 --with-colons --print-mds
+ grep c
+ echo testing\c
+ echo 1,2,3
+ echo -n testing
+ echo 1,2,3
+ sed s/-n/xn/
+ grep xn
+ echo_n_n=
+ echo_n_c=

+ echo_n_init=yes
+ echo abcdefghijklmnopqrstuvwxyz

:1:AD5DEB9B35AB55595BC8312CF1EE134F:
:2:7FDFFACEC05073FD23135CF94868A0076ABF3953:
:3:13F4E18DD89D9611E224C7A73E25C6A42BFF090F:
:11:DBB9A410F16C536637D928B37682A522E3A473864EF6915715DE81B3:
:8:DC6BEFD7DC150815AC9DA4477A059849BC60CE64B052F7D73F33239ADB80F292:
:9:5EAB880F1B7A7E5E888A745B650D705DF7DD1960728BE123088C897B5BCFD37042BE1EFD172CFC0B09E1705EB190A8F4:
:10:6B779E094FB3286174E9E7D08C3D65D6755AC29ACDBEDE2B48E35EA1E9F040E089F62ED8C1378AF2D999F4562334BB071D7493A
FEA19E62C00678F59AA624126:

which is, obviously, not correct.

I use dash myself and I have no problems. dash supports echo -n and
he test is supposed to detect this. However, in your case neither \c
nor -n is supported and thus the LF is appended. I don't known for
sure why this is done; the ChangeLog entry for this is

  Wed Aug  4 10:34:18 CEST 1999  Werner Koch  <wk@isil.d.shuttle.de>
  • defs.inc (echo_n): New and used instead of /bin/echo "\c"

Probably we never hit that case. The test for echo as used by
configure is too complex to use here. Anyway, something is wrong with
your dash version: It does not neither grok -n nor \c.

AFAIK dash does not support "echo -n". From "man dash":
echo args...

            Print the arguments on the standard output, separated by spaces.

            No arguments or backslash sequences are supported as they are not

portable. They will be printed out exactly as

            passed in.

            You can replace `echo -n ...` with the portable `printf %s ...`

construct.

From my dash man page:

  echo [-n] args...
            Print the arguments on the standard output, separated by spaces.
            Unless the -n option is present, a new
            line is output following the arguments.

The version is 0.5.7 and the debian docs say.

This package was debianized by Mark W. Eichin eichin@kitten.gen.ma.us on
Mon, 24 Feb 1997 16:00:16 -0500.

This package was re-ported from NetBSD and debianized by
Herbert Xu herbert@debian.org on Thu, 19 Jun 1997 19:29:16 +1000.

This package was adopted by Gerrit Pape <pape@smarden.org> on
Fri, 28 May 2004 18:38:18 +0000.

It was downloaded from http://gondor.apana.org.au/~herbert/dash/files/

The problem with printf is that it is not availabale on older Unices.

Right after I wrote my last reply I noticed that Gentoo patches dash to
"neuter" its echo builtin so that it recognizes neither options nor escape
sequences. So this is Gentoo (and derivatives) specific.

See (if you care) the discussions that led to this behaviour:
http://bugs.gentoo.org/337329
http://bugs.gentoo.org/527848

I tend to add a test for printf but given that we will soon replace the entire
test suite I doubt that this will be the best use of my time.

Do whatever you prefer. I'm sorry that I bothered you with what is, after all, a
local problem. I'll try to push a workaround for this in Gentoo.

Thanks for your patience.

In data martedì 3 maggio 2016 15:13:04 CEST, hai scritto:

Werner Koch <wk@gnupg.org> added the comment:

From my dash man page:

echo [-n] args...
          Print the arguments on the standard output, separated by spaces.

Unless the -n option is present, a new

line is output following the arguments.

The version is 0.5.7 and the debian docs say.

Right after I wrote my last reply I noticed that Gentoo patches dash to
"neuter" its echo builtin so that it recognizes neither options nor escape
sequences. So this is Gentoo (and derivatives) specific.

Fixed in 2.1.14 with the switch to Scheme-based tests.

justus claimed this task.