}
static gboolean
-rspamd_dkim_relaxed_body_step (GChecksum *ck, const gchar **start, guint remain)
+rspamd_dkim_relaxed_body_step (GChecksum *ck, const gchar **start, guint size,
+ guint *remain)
{
const gchar *h;
static gchar buf[BUFSIZ];
guint len, inlen;
gboolean got_sp, finished = FALSE;
- if (remain > sizeof (buf)) {
+ if (size > sizeof (buf)) {
len = sizeof (buf);
}
else {
- len = remain;
+ len = size;
finished = TRUE;
}
inlen = sizeof (buf) - 1;
#if 0
msg_debug ("update signature with buffer: %*s", t - buf, buf);
#endif
- g_checksum_update (ck, buf, t - buf);
+ if (*remain > 0) {
+ size_t cklen = MIN(t - buf, *remain);
+ g_checksum_update (ck, buf, cklen);
+ *remain = *remain - cklen;
+ }
return !finished;
}
static gboolean
-rspamd_dkim_simple_body_step (GChecksum *ck, const gchar **start, guint remain)
+rspamd_dkim_simple_body_step (GChecksum *ck, const gchar **start, guint size,
+ guint *remain)
{
const gchar *h;
static gchar buf[BUFSIZ];
guint len, inlen;
gboolean finished = FALSE;
- if (remain > sizeof (buf)) {
+ if (size > sizeof (buf)) {
len = sizeof (buf);
}
else {
- len = remain;
+ len = size;
finished = TRUE;
}
inlen = sizeof (buf) - 1;
#if 0
msg_debug ("update signature with buffer: %*s", t - buf, buf);
#endif
- g_checksum_update (ck, buf, t - buf);
+ if (*remain > 0) {
+ size_t cklen = MIN(t - buf, *remain);
+ g_checksum_update (ck, buf, cklen);
+ *remain = *remain - cklen;
+ }
return !finished;
}
const gchar *end)
{
const gchar *p;
+ guint remain = ctx->len ? ctx->len : end - start;
if (start == NULL) {
/* Empty body */
if (ctx->body_canon_type == DKIM_CANON_SIMPLE) {
/* Simple canonization */
while (rspamd_dkim_simple_body_step (ctx->body_hash, &start,
- end - start)) ;
+ end - start, &remain)) ;
}
else {
while (rspamd_dkim_relaxed_body_step (ctx->body_hash, &start,
- end - start)) ;
+ end - start, &remain)) ;
}
}
return TRUE;
}
/* Start canonization of body part */
- if (headers_end) {
- if (ctx->len == 0 || (gint)ctx->len > end - headers_end) {
- body_end = end;
- }
- else {
- /* Strip message */
- body_end = headers_end + ctx->len;
- }
- }
- else {
- body_end = end;
- }
+ body_end = end;
if (!rspamd_dkim_canonize_body (ctx, headers_end, body_end)) {
return DKIM_RECORD_ERROR;
}