aboutsummaryrefslogtreecommitdiffstats
path: root/src/libserver/dkim.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rspamd.com>2022-06-29 21:00:14 +0100
committerVsevolod Stakhov <vsevolod@rspamd.com>2022-06-29 21:00:14 +0100
commitcd615af74402fdd6429cc4600c653d015ab035b5 (patch)
tree554a1a622aaf59ec248d646548391451a920d9b2 /src/libserver/dkim.c
parent0049505d4f2b5b3f9510a1b5472a56dc4415cba3 (diff)
downloadrspamd-cd615af74402fdd6429cc4600c653d015ab035b5.tar.gz
rspamd-cd615af74402fdd6429cc4600c653d015ab035b5.zip
[Minor] Fix confusing with variable type and re-use
Diffstat (limited to 'src/libserver/dkim.c')
-rw-r--r--src/libserver/dkim.c22
1 files changed, 16 insertions, 6 deletions
diff --git a/src/libserver/dkim.c b/src/libserver/dkim.c
index 1077c49c6..575a9c5e0 100644
--- a/src/libserver/dkim.c
+++ b/src/libserver/dkim.c
@@ -806,7 +806,7 @@ rspamd_create_dkim_context (const gchar *sig,
GError **err)
{
const gchar *p, *c, *tag = NULL, *end;
- gsize taglen;
+ gint taglen;
gint param = DKIM_PARAM_UNKNOWN;
const EVP_MD *md_alg;
time_t now;
@@ -860,7 +860,7 @@ rspamd_create_dkim_context (const gchar *sig,
switch (state) {
case DKIM_STATE_TAG:
if (g_ascii_isspace (*p)) {
- taglen = p - c;
+ taglen = (int)(p - c);
while (*p && g_ascii_isspace (*p)) {
/* Skip spaces before '=' sign */
p++;
@@ -889,7 +889,17 @@ rspamd_create_dkim_context (const gchar *sig,
}
else {
taglen++;
- p++;
+
+ if (taglen > G_MAXINT8) {
+ g_set_error (err,
+ DKIM_ERROR,
+ DKIM_SIGERROR_UNKNOWN,
+ "too long dkim tag");
+ state = DKIM_STATE_ERROR;
+ }
+ else {
+ p++;
+ }
}
break;
case DKIM_STATE_AFTER_TAG:
@@ -1256,11 +1266,11 @@ rspamd_create_dkim_context (const gchar *sig,
}
/* Now create dns key to request further */
- taglen = strlen (ctx->domain) + strlen (ctx->selector) +
+ gsize dnslen = strlen (ctx->domain) + strlen (ctx->selector) +
sizeof (DKIM_DNSKEYNAME) + 2;
- ctx->dns_key = rspamd_mempool_alloc (ctx->pool, taglen);
+ ctx->dns_key = rspamd_mempool_alloc (ctx->pool, dnslen);
rspamd_snprintf (ctx->dns_key,
- taglen,
+ dnslen,
"%s.%s.%s",
ctx->selector,
DKIM_DNSKEYNAME,