Skip to content

libopendkim: don't error on missing CRLF when l= body length tag is used#339

Merged
thegushi merged 2 commits into
trusteddomainproject:developfrom
thegushi:issue-45-l-tag-crlf
May 25, 2026
Merged

libopendkim: don't error on missing CRLF when l= body length tag is used#339
thegushi merged 2 commits into
trusteddomainproject:developfrom
thegushi:issue-45-l-tag-crlf

Conversation

@thegushi
Copy link
Copy Markdown
Collaborator

Summary

When a DKIM signature includes l=, the MTA delivers only that many body bytes and replies with SMFIS_SKIP. The truncated body may not end with CRLF - which is expected per RFC 6376 §3.7: both simple and relaxed canonicalization append a CRLF to any non-empty body that doesn't already end with one.

The bug: dkim_canon_closebody() returned DKIM_STAT_SYNTAX ("CRLF at end of body missing") whenever there was buffered content without a trailing CRLF, unless DKIM_LIBFLAGS_FIXCRLF was set. With l= this was a false positive.

Fix: when canon_remain != -1 (i.e. l= was present and set a body length limit), always take the append-CRLF path. canon_remain is set from the l= value during signature parsing and decrements to 0 after the body bytes are processed - it is never -1 when l= is in use. The error path is preserved for signatures without l=, consistent with mskucherawy's comment in the original thread.

Tests added:

  • t-test206: sign with explicit body length and body without CRLF; verify that both sign and verify succeed
  • t-test207: regression - without l=, body without CRLF still raises DKIM_STAT_SYNTAX

Fixes #45

Test plan

  • make check passes including t-test206 and t-test207
  • CI passes

When a DKIM signature includes the l= body length tag, the MTA delivers
only that many bytes of body and OpenDKIM returns SMFIS_SKIP.  The
truncated body may not end with CRLF, which is expected: RFC 6376
section 3.7 specifies that body canonicalization appends CRLF to a
non-empty body that doesn't already end with one.  Treating this as a
syntax error was a false positive.

When canon_remain != -1 (i.e. l= was used), always take the append-CRLF
path in dkim_canon_closebody() rather than erroring.  The error is still
raised when no body length limit was in use, consistent with the
original intent.

Fixes trusteddomainproject#45
…fix

t-test149 uses SIG2 which has l=340.  After the fix in dkim-canon.c,
missing CRLF is no longer a syntax error when a body length tag is
present, so the first run no longer returns DKIM_STAT_SYNTAX.  The
regression test that confirms DKIM_STAT_SYNTAX is still raised without
l= is covered by the new t-test207.
@thegushi thegushi merged commit 8ba0915 into trusteddomainproject:develop May 25, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant