why is GPG_ERR_SEXP_ZERO_PREFIX an error for gcry_sexp_canon_len()?

Daniel Kahn Gillmor dkg at fifthhorseman.net
Tue May 14 22:56:17 CEST 2019


Over in https://dev.gnupg.org/T4501 i discovered that
gcry_sexp_canon_len() can fail and report an error if the S-expression
contains a zero-length string.

In particular, it will fail with errcode returning
GPG_ERR_SEXP_ZERO_PREFIX.

Why is it an error to have a string of zero-length in an s-expression in
canonical form?

i tried to do some testing with higher-level S-expression tools,
including dumpsexp (from gcrypt) and sexp-conv (from nettle).

nettle doesn't seem to have a problem with it, and dumpsexp also doesn't
have a problem with it in non-canonical form, but it reports an error in
"canonical" form.

Here is a simple test that shows the weirdness:

----------------------
0 dkg at alice:~$ echo '(foo: (bar: ""))' > sexp
0 dkg at alice:~$ sexp-conv -s canonical < sexp | hd
00000000  28 34 3a 66 6f 6f 3a 28  34 3a 62 61 72 3a 30 3a  |(4:foo:(4:bar:0:|
00000010  29 29                                             |))|
00000012
0 dkg at alice:~$ dumpsexp < sexp 
foo:bar:00000000  28 66 6f 6f 3a 20 28 62  61 72 3a 20 22 22 29 29  |(foo: (bar: ""))|
00000010  0a                                                |.|
0 dkg at alice:~$ sexp-conv -s canonical < sexp | dumpsexp
00000000  28 34 3a 66 6f 6f 3a 28  34 3a 62 61 72 3a 30     |(4:foo:(4:bar:0|
                                                     ^                     ^
          Error: zero prefixed length
0000000f                                                3a  |               :|
                                                        ^                   ^
          Error: no data length
00000010                                                    |                |
00000010  29 29                                             |))|
0 dkg at alice:~$
----------------------

Can someone who understands S-Expressions better than me point me to
documentation that will help me understand why gcry_sexp_canon_len()
should treat this as an error?

       --dkg
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 227 bytes
Desc: not available
URL: <https://lists.gnupg.org/pipermail/gcrypt-devel/attachments/20190514/4aedb214/attachment.sig>


More information about the Gcrypt-devel mailing list