commit cd615af: [Minor] Fix confusing with variable type and re-use
Vsevolod Stakhov
vsevolod at rspamd.com
Wed Jun 29 20:07:03 UTC 2022
Author: Vsevolod Stakhov
Date: 2022-06-29 21:00:14 +0100
URL: https://github.com/rspamd/rspamd/commit/cd615af74402fdd6429cc4600c653d015ab035b5
[Minor] Fix confusing with variable type and re-use
---
src/libserver/dkim.c | 22 ++++++++++++++++------
1 file 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,
More information about the Commits
mailing list