break;
default:
- assert (0);
+ g_assert_not_reached ();
}
}
/* Read macro name */
switch (g_ascii_tolower (*p)) {
case 'i':
- macro_len = rspamd_strlcpy (ip_buf,
- rspamd_inet_address_to_string (task->from_addr),
- sizeof (ip_buf));
- macro_value = ip_buf;
+ if (task->from_addr) {
+ macro_len = rspamd_strlcpy (ip_buf,
+ rspamd_inet_address_to_string (task->from_addr),
+ sizeof (ip_buf));
+ macro_value = ip_buf;
+ }
+ else {
+ macro_len = rspamd_snprintf (ip_buf, sizeof (ip_buf),
+ "127.0.0.1");
+ macro_value = ip_buf;
+ }
break;
case 's':
- macro_len = strlen (rec->sender);
- macro_value = rec->sender;
+ if (rec->sender) {
+ macro_len = strlen (rec->sender);
+ macro_value = rec->sender;
+ }
+ else {
+ macro_len = sizeof ("unknown") - 1;
+ macro_value = "unknown";
+ }
break;
case 'l':
- macro_len = strlen (rec->local_part);
- macro_value = rec->local_part;
+ if (rec->local_part) {
+ macro_len = strlen (rec->local_part);
+ macro_value = rec->local_part;
+ }
+ else {
+ macro_len = sizeof ("unknown") - 1;
+ macro_value = "unknown";
+ }
break;
case 'o':
- macro_len = strlen (rec->sender_domain);
- macro_value = rec->sender_domain;
+ if (rec->sender_domain) {
+ macro_len = strlen (rec->sender_domain);
+ macro_value = rec->sender_domain;
+ }
+ else {
+ macro_len = sizeof ("unknown") - 1;
+ macro_value = "unknown";
+ }
break;
case 'd':
- macro_len = strlen (resolved->cur_domain);
- macro_value = resolved->cur_domain;
+ if (resolved && resolved->cur_domain) {
+ macro_len = strlen (resolved->cur_domain);
+ macro_value = resolved->cur_domain;
+ }
+ else {
+ macro_len = sizeof ("unknown") - 1;
+ macro_value = "unknown";
+ }
break;
case 'v':
- if (rspamd_inet_address_get_af (task->from_addr) == AF_INET) {
- macro_len = sizeof ("in-addr") - 1;
- macro_value = "in-addr";
+ if (task->from_addr) {
+ if (rspamd_inet_address_get_af (task->from_addr) == AF_INET) {
+ macro_len = sizeof ("in-addr") - 1;
+ macro_value = "in-addr";
+ } else {
+ macro_len = sizeof ("ip6") - 1;
+ macro_value = "ip6";
+ }
}
else {
- macro_len = sizeof ("ip6") - 1;
- macro_value = "ip6";
+ macro_len = sizeof ("in-addr") - 1;
+ macro_value = "in-addr";
}
break;
case 'h':
macro_value = task->helo;
}
}
+ else {
+ macro_len = sizeof ("unknown") - 1;
+ macro_value = "unknown";
+ }
break;
default:
- macro_len = 0;
- macro_value = NULL;
msg_info_spf (
"<%s>: spf error for domain %s: unknown or "
"unsupported spf macro %c in %s",