Skip to content

Commit

Permalink
libopenarc: Check length of header field name more tightly.
Browse files Browse the repository at this point in the history
From the restriction of RFC5322 section 2.1.1 and section 2.2,
length of email header field name cannot be more than 997.

With this commit, we define a constant macro for it, and then
apply this restriction on parsing header field. Also, reduce
size of a buffer for copying header field name.

* libopenarc/arc.h (ARC_MAXLINELEN, ARC_MAXHDRNAMELEN): New macros.
* libopenarc/arc.c (arc_parse_header_field, ar_eoh):
  Use ARC_MAXHDRNAMELEN as maximum length of header field names.

trusteddomainproject/OpenARC#179
  • Loading branch information
futatuki authored and flowerysong committed Oct 2, 2024
1 parent 92d9ac8 commit d316f36
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 3 additions & 3 deletions libopenarc/arc.c
Original file line number Diff line number Diff line change
Expand Up @@ -2466,7 +2466,7 @@ arc_parse_header_field(ARC_MESSAGE *msg, u_char *hdr, size_t hlen,
end--;

/* don't allow incredibly large field names */
if (end - hdr > ARC_MAXHEADER)
if (end - hdr > ARC_MAXHDRNAMELEN)
return ARC_STAT_SYNTAX;

/* don't allow a field name containing a semicolon */
Expand Down Expand Up @@ -2816,8 +2816,8 @@ arc_eoh(ARC_MESSAGE *msg)

for (h = msg->arc_hhead; h != NULL; h = h->hdr_next)
{
char hnbuf[ARC_MAXHEADER + 1];
assert(h->hdr_namelen <= ARC_MAXHEADER);
char hnbuf[ARC_MAXHDRNAMELEN + 1];
assert(h->hdr_namelen <= ARC_MAXHDRNAMELEN);

memset(hnbuf, '\0', sizeof hnbuf);
strncpy(hnbuf, h->hdr_text, h->hdr_namelen);
Expand Down
2 changes: 2 additions & 0 deletions libopenarc/arc.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ extern "C" {
#define ARC_HDRMARGIN 75 /* "standard" header margin */
#define ARC_MAXHEADER 4096 /* buffer for caching one header */
#define ARC_MAXHOSTNAMELEN 256 /* max. FQDN we support */
#define ARC_MAXLINELEN 1000 /* physical line limit (RFC5321) */
#define ARC_MAXHDRNAMELEN (ARC_MAXLINELEN - 3) /* deduct ":" CRLF */

#define ARC_AR_HDRNAME "ARC-Authentication-Results"
#define ARC_DEFAULT_MINKEYSIZE 1024
Expand Down

0 comments on commit d316f36

Please sign in to comment.