commit cd6f9b0334b79f24cf4c6a3a098bc3aa11e6f477 from: Martijn van Duren date: Wed Oct 23 07:25:28 2019 UTC Fix couple off by 1s. Found and fix tested by Mikolaj Kucharski mikolaj kucharski name commit - 2cd46d73b60506fa8da4a5f9dba082d709502b53 commit + cd6f9b0334b79f24cf4c6a3a098bc3aa11e6f477 blob - 6556177889fc16102f015eda4e368e3d68b9451f blob + cd8936cf464c880415aeeae99c4c3de9758604e1 --- Makefile +++ Makefile @@ -1,3 +1,4 @@ +LOCALBASE?= /usr/local/ PROG= filter-dkimsign MAN= filter-dkimsign.8 BINDIR= ${LOCALBASE}/libexec/smtpd/ blob - 067c71b06ad1ea0df8fc7b69e999e6b2b39067ab blob + 890474469a6d8b245f380cfc663aaa34664b7ef0 --- main.c +++ main.c @@ -412,7 +412,7 @@ dkim_parse_header(struct dkim_message *message, char * fieldname = 1; for (r = w = 0; line[r] != '\0'; r++) { if (line[r] == ':' && fieldname) { - if (line[w - 1] == ' ') + if (w > 0 && line[w - 1] == ' ') line[w - 1] = ':'; else line[w++] = ':'; @@ -424,7 +424,7 @@ dkim_parse_header(struct dkim_message *message, char * } if (line[r] == ' ' || line[r] == '\t' || line[r] == '\r' || line[r] == '\n') { - if (r != 0 && line[w - 1] == ' ') + if (r != 0 && w != 0 && line[w - 1] == ' ') continue; else line[w++] = ' '; @@ -434,7 +434,7 @@ dkim_parse_header(struct dkim_message *message, char * } else line[w++] = line[r]; } - linelen = line[w - 1] == ' ' ? w - 1 : w; + linelen = (w != 0 && line[w - 1] == ' ') ? w - 1 : w; line[linelen] = '\0'; } else linelen = strlen(line); @@ -495,7 +495,7 @@ dkim_parse_body(struct dkim_message *message, char *li } else line[w++] = line[r]; } - linelen = line[w - 1] == ' ' ? w - 1 : w; + linelen = (w != 0 && line[w - 1] == ' ') ? w - 1 : w; line[linelen] = '\0'; } else linelen = strlen(line);