commit 5f5f9df0fb9731664a2b3fe1c002f569aaa9239e from: Kirill A. Korinsky date: Wed Jan 29 00:55:58 2025 UTC Improve serialization of AR header Here two fixes: (1) avoid loop when checkpoint starts from whitespace, and (2) avoid infintity loop on very long last field. commit - 0379d2666788c6c4319eda65d24f633427832d4b commit + 5f5f9df0fb9731664a2b3fe1c002f569aaa9239e blob - aed4e74674b95761391ab7491bfc18a2d8573f3c blob + 886cf1e7e01098aa49c5e1a3511f8c6f41466e68 --- main.c +++ main.c @@ -1664,8 +1664,7 @@ void dkim_ar_print(struct osmtpd_ctx *ctx, const char *start) { const char *scan, *checkpoint, *ncheckpoint; - size_t arlen = 0; - int first = 1, arid = 1; + int arlen = 0, first = 1, arid = 1; checkpoint = start; ncheckpoint = osmtpd_ltok_skip_hdr_name(start, 0) + 1; @@ -1675,10 +1674,16 @@ dkim_ar_print(struct osmtpd_ctx *ctx, const char *star else arlen++; if (arlen >= AUTHENTICATION_RESULTS_LINELEN) { - osmtpd_filter_dataline(ctx, "%s%.*s", first ? "" : "\t", - (int)((checkpoint == start ? - ncheckpoint : checkpoint) - start), start); + arlen = (int)(checkpoint - start); + if (arlen <= 0) { + arlen = (int)(ncheckpoint - start); + checkpoint = ncheckpoint; + } + osmtpd_filter_dataline(ctx, "%s%.*s", first ? "" : "\t", + arlen, start); start = osmtpd_ltok_skip_cfws(checkpoint, 1); + if (*start == '\0') + return; scan = start; arlen = 8; first = 0;