libopendkim: don't error on missing CRLF when l= body length tag is used#339
Merged
thegushi merged 2 commits intoMay 25, 2026
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When a DKIM signature includes
l=, the MTA delivers only that many body bytes and replies withSMFIS_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()returnedDKIM_STAT_SYNTAX("CRLF at end of body missing") whenever there was buffered content without a trailing CRLF, unlessDKIM_LIBFLAGS_FIXCRLFwas set. Withl=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_remainis set from thel=value during signature parsing and decrements to 0 after the body bytes are processed - it is never -1 whenl=is in use. The error path is preserved for signatures withoutl=, 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 succeedt-test207: regression - withoutl=, body without CRLF still raisesDKIM_STAT_SYNTAXFixes #45
Test plan
make checkpasses including t-test206 and t-test207