Skip to content

Commit

Permalink
Address reopened issue trusteddomainproject#158: Allow for quotes whe…
Browse files Browse the repository at this point in the history
…n parsing Received-SPF.
  • Loading branch information
Murray S. Kucherawy committed Apr 11, 2021
1 parent 4269fd5 commit d72e1ec
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
30 changes: 21 additions & 9 deletions opendmarc/opendmarc.c
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,7 @@ dmarcf_parse_received_spf(char *str, char *envfrom)
{
_Bool in_result = TRUE;
_Bool escaped = FALSE;
_Bool quoting = FALSE;
int parens = 0;
char *p;
char *r;
Expand All @@ -466,15 +467,7 @@ dmarcf_parse_received_spf(char *str, char *envfrom)

for (p = str; *p != '\0'; p++)
{
if (*p == '(')
{
parens++;
}
else if (*p == ')' && parens > 0)
{
parens--;
}
else if (escaped)
if (escaped)
{
if (parens == 0 && r < end)
*r++ = *p;
Expand All @@ -484,11 +477,30 @@ dmarcf_parse_received_spf(char *str, char *envfrom)
{
escaped = TRUE;
}
else if (*p == '(')
{
parens++;
}
else if (*p == ')' && parens > 0)
{
parens--;
}
else if (parens == 0)
{
if (*p == '"')
{
/* entering/leaving a quoted substring */
quoting = !quoting;
continue;
}

/* a possibly meaningful character */
if (isascii(*p) && isspace(*p))
{
/* a space while quoting; just continue */
if (quoting)
continue;

if (in_result)
{
in_result = FALSE;
Expand Down
2 changes: 1 addition & 1 deletion opendmarc/tests/t-verify-received-spf-good.lua
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ end

-- send headers
-- mt.rcptto() is called implicitly
if mt.header(conn, "Received-SPF", "pass identity=mailfrom; [email protected]") ~= nil then
if mt.header(conn, "Received-SPF", "pass identity=mailfrom; envelope-from=\"[email protected]\"") ~= nil then
error("mt.header(Received-SPF) failed")
end
if mt.getreply(conn) ~= SMFIR_CONTINUE then
Expand Down

0 comments on commit d72e1ec

Please sign in to comment.