Re: Multiple instances of a header field

From: Ken Murchison <murch_at_andrew.cmu.edu>
Date: Fri, 08 Jun 2012 15:21:31 -0400

On 06/08/2012 12:30 PM, Ken Murchison wrote:
> Does libopendkim properly handle multiple instances of a header field
> per section 5.4.2 of RFC 6376 (where they are supposed to be hashed in
> last-to-first order)?
>
> My reading of the code leads me to believe that they are hashed in the
> order that they are added with dkim_header(). If so, then the
> dkim_chunk() interface is broken since it will process multiple
> instances first-to-last.
>
> Would it not make sense to have dkim_header() reverse the order of the
> headers as they are added (add headers to the head of the internal
> header list, rather than the tail)?
>
> Of course, if we make this change, any existing applications that
> already call dkim_header() in last-to-first order will be broken.
>
> Thoughts?
>


As an alternative to changing the dkim_header() behavior, here is a
patch that reverses the order of the headers when using dkim_chunk() so
that they get processed last-to-first.

diff --git a/libopendkim/dkim.c b/libopendkim/dkim.c
index 0fe801c..a503349 100644
--- a/libopendkim/dkim.c
+++ b/libopendkim/dkim.c

_at_@ -6488,6 +6526,23 @@ dkim_eoh(DKIM *dkim)
  {
          assert(dkim != NULL);

+ if (dkim->dkim_chunkstate == DKIM_CHUNKSTATE_HEADER)
+ {
+ /* reverse the order of the headers */
+ struct dkim_header *hdr, *next;
+
+ hdr = dkim->dkim_hhead;
+ dkim->dkim_hhead = NULL;
+ dkim->dkim_htail = hdr;
+ while (hdr != NULL)
+ {
+ next = hdr->hdr_next;
+ hdr->hdr_next = dkim->dkim_hhead;
+ dkim->dkim_hhead = hdr;
+ hdr = next;
+ }
+ }
+
          if (dkim->dkim_mode == DKIM_MODE_VERIFY)
                  return dkim_eoh_verify(dkim);
          else



-- 
Kenneth Murchison
Principal Systems Software Engineer
Carnegie Mellon University
Received on Fri Jun 08 2012 - 19:21:51 PST

This archive was generated by hypermail 2.3.0 : Mon Oct 29 2012 - 23:33:33 PST