Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Escape quotation marks when logging SMTP strings #88

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/src/deliver.c
Original file line number Diff line number Diff line change
Expand Up @@ -845,7 +845,7 @@ if (LOGGING(tls_certificate_verified) && addr->cipher)
"yes"
: "no");
if (LOGGING(tls_peerdn) && addr->peerdn)
g = string_append(g, 3, US" DN=\"", string_printing(addr->peerdn), US"\"");
g = string_append(g, 3, US" DN=\"", string_printing2(addr->peerdn, SP_QUOT), US"\"");
return g;
}
#endif
Expand Down
1 change: 1 addition & 0 deletions src/src/macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ allow tabs & spaces. A macro just makes life a bit easier. */
#define string_printing(s) string_printing2((s), 0)
#define SP_TAB BIT(0)
#define SP_SPACE BIT(1)
#define SP_QUOT BIT(2)


/* We need a special return code for "no recipients and failed to send an error
Expand Down
2 changes: 1 addition & 1 deletion src/src/receive.c
Original file line number Diff line number Diff line change
Expand Up @@ -4072,7 +4072,7 @@ if (LOGGING(tls_cipher) && tls_in.cipher)
if (LOGGING(tls_certificate_verified) && tls_in.cipher)
g = string_append(g, 2, US" CV=", tls_in.certificate_verified ? "yes":"no");
if (LOGGING(tls_peerdn) && tls_in.peerdn)
g = string_append(g, 3, US" DN=\"", string_printing(tls_in.peerdn), US"\"");
g = string_append(g, 3, US" DN=\"", string_printing2(tls_in.peerdn, SP_QUOT), US"\"");
if (LOGGING(tls_sni) && tls_in.sni)
g = string_append(g, 2, US" SNI=", string_printing2(tls_in.sni, SP_TAB|SP_SPACE));
#endif
Expand Down
29 changes: 15 additions & 14 deletions src/src/smtp_in.c
Original file line number Diff line number Diff line change
Expand Up @@ -710,8 +710,8 @@ for(;;)
log_write(0, LOG_MAIN|LOG_REJECT, "SMTP protocol synchronization error "
"(next input sent too soon: pipelining was not advertised): "
"rejected \"%s\" %s next input=\"%s\"%s",
smtp_cmd_buffer, host_and_ident(TRUE),
string_printing(string_copyn(smtp_inptr, n)),
string_printing2(smtp_cmd_buffer, SP_QUOT), host_and_ident(TRUE),
string_printing2(string_copyn(smtp_inptr, n), SP_QUOT),
smtp_inend - smtp_inptr > n ? "..." : "");
(void) synprot_error(L_smtp_protocol_error, 554, NULL,
US"SMTP synchronization error");
Expand Down Expand Up @@ -1846,7 +1846,7 @@ if (LOGGING(tls_cipher) && tls_in.cipher)
if (LOGGING(tls_certificate_verified) && tls_in.cipher)
g = string_append(g, 2, US" CV=", tls_in.certificate_verified? "yes":"no");
if (LOGGING(tls_peerdn) && tls_in.peerdn)
g = string_append(g, 3, US" DN=\"", string_printing(tls_in.peerdn), US"\"");
g = string_append(g, 3, US" DN=\"", string_printing2(tls_in.peerdn, SP_QUOT), US"\"");
if (LOGGING(tls_sni) && tls_in.sni)
g = string_append(g, 2, US" SNI=", string_printing2(tls_in.sni, SP_TAB|SP_SPACE));
return g;
Expand Down Expand Up @@ -2873,7 +2873,7 @@ if (!f.sender_host_unknown)
errno = 0;
if (!(tcp_wrappers_name = expand_string(tcp_wrappers_daemon_name)))
log_write(0, LOG_MAIN|LOG_PANIC_DIE, "Expansion of \"%s\" "
"(tcp_wrappers_name) failed: %s", string_printing(tcp_wrappers_name),
"(tcp_wrappers_name) failed: %s", string_printing2(tcp_wrappers_name, SP_QUOT),
expand_string_message);

if (!hosts_ctl(tcp_wrappers_name,
Expand Down Expand Up @@ -3095,7 +3095,7 @@ if (!check_sync())
log_write(0, LOG_MAIN|LOG_REJECT, "SMTP protocol "
"synchronization error (input sent without waiting for greeting): "
"rejected connection from %s input=\"%s\"", host_and_ident(TRUE),
string_printing(string_copyn(smtp_inptr, n)));
string_printing2(string_copyn(smtp_inptr, n)), SP_QUOT);
smtp_printf("554 SMTP synchronization error\r\n", FALSE);
return FALSE;
}
Expand Down Expand Up @@ -3152,14 +3152,14 @@ int yield = -1;

log_write(type, LOG_MAIN, "SMTP %s error in \"%s\" %s %s",
type == L_smtp_syntax_error ? "syntax" : "protocol",
string_printing(smtp_cmd_buffer), host_and_ident(TRUE), errmess);
string_printing2(smtp_cmd_buffer, SP_QUOT), host_and_ident(TRUE), errmess);

if (++synprot_error_count > smtp_max_synprot_errors)
{
yield = 1;
log_write(0, LOG_MAIN|LOG_REJECT, "SMTP call from %s dropped: too many "
"syntax or protocol errors (last command was \"%s\", %s)",
host_and_ident(FALSE), string_printing(smtp_cmd_buffer),
host_and_ident(FALSE), string_printing2(smtp_cmd_buffer, SP_QUOT),
string_from_gstring(s_connhad_log(NULL))
);
}
Expand Down Expand Up @@ -4286,7 +4286,7 @@ while (done <= 0)
{
log_write(0, LOG_MAIN|LOG_REJECT, "SMTP call from %s dropped: too many "
"syntax or protocol errors (last command was \"%s\", %s)",
host_and_ident(FALSE), string_printing(smtp_cmd_buffer),
host_and_ident(FALSE), string_printing2(smtp_cmd_buffer, SP_QUOT),
string_from_gstring(s_connhad_log(NULL))
);
done = 1;
Expand Down Expand Up @@ -6010,8 +6010,8 @@ while (done <= 0)
"(next input sent too soon: pipelining was%s advertised): "
"rejected \"%s\" %s next input=\"%s\"",
f.smtp_in_pipelining_advertised ? "" : " not",
smtp_cmd_buffer, host_and_ident(TRUE),
string_printing(smtp_inptr));
string_printing2(smtp_cmd_buffer, SP_QUOT), host_and_ident(TRUE),
string_printing2(smtp_inptr, SP_QUOT));
smtp_notquit_exit(US"synchronization-error", US"554",
US"SMTP synchronization error");
done = 1; /* Pretend eof - drops connection */
Expand All @@ -6021,10 +6021,11 @@ while (done <= 0)
case TOO_MANY_NONMAIL_CMD:
s = smtp_cmd_buffer;
while (*s != 0 && !isspace(*s)) s++;
*s = 0;
incomplete_transaction_log(US"too many non-mail commands");
log_write(0, LOG_MAIN|LOG_REJECT, "SMTP call from %s dropped: too many "
"nonmail commands (last was \"%.*s\")", host_and_ident(FALSE),
(int)(s - smtp_cmd_buffer), smtp_cmd_buffer);
"nonmail commands (last was \"%s\")", host_and_ident(FALSE),
string_printing2(smtp_cmd_buffer, SP_QUOT));
smtp_notquit_exit(US"bad-commands", US"554", US"Too many nonmail commands");
done = 1; /* Pretend eof - drops connection */
break;
Expand All @@ -6040,15 +6041,15 @@ while (done <= 0)
{
log_write(L_smtp_syntax_error, LOG_MAIN,
"SMTP syntax error in \"%s\" %s %s",
string_printing(smtp_cmd_buffer), host_and_ident(TRUE),
string_printing2(smtp_cmd_buffer, SP_QUOT), host_and_ident(TRUE),
US"unrecognized command");
incomplete_transaction_log(US"unrecognized command");
smtp_notquit_exit(US"bad-commands", US"500",
US"Too many unrecognized commands");
done = 2;
log_write(0, LOG_MAIN|LOG_REJECT, "SMTP call from %s dropped: too many "
"unrecognized commands (last was \"%s\")", host_and_ident(FALSE),
string_printing(smtp_cmd_buffer));
string_printing2(smtp_cmd_buffer, SP_QUOT));
}
else
done = synprot_error(L_smtp_syntax_error, 500, NULL,
Expand Down
2 changes: 2 additions & 0 deletions src/src/string.c
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ while (*t)
if ( !mac_isprint(c)
|| flags & SP_TAB && c == '\t'
|| flags & SP_SPACE && c == ' '
|| flags & SP_QUOT && c == '\"'
) nonprintcount++;
length++;
}
Expand All @@ -323,6 +324,7 @@ for (t = s; *t; )
if ( mac_isprint(c)
&& (!(flags & SP_TAB) || c != '\t')
&& (!(flags & SP_SPACE) || c != ' ')
&& (!(flags & SP_QUOT) || c != '\"')
)
*tt++ = *t++;
else
Expand Down
2 changes: 1 addition & 1 deletion src/src/tls-openssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1180,7 +1180,7 @@ else
log_write(0, LOG_MAIN,
"[%s] SSL verify error%s: certificate name mismatch: DN=\"%s\" H=\"%s\"",
tlsp == &tls_out ? deliver_host_address : sender_host_address,
extra, dn, verify_cert_hostnames);
extra, string_printing2(dn, SP_QUOT), verify_cert_hostnames);
*calledp = TRUE;
if (!*optionalp)
{
Expand Down