commit 1256d7a0bbd5e02619cabac764a79970fb9857d3 from: Kirill A. Korinsky date: Mon Jun 2 19:56:29 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 - 348f2e63579da7efa4351bbd45702f4632acddd7 commit + 1256d7a0bbd5e02619cabac764a79970fb9857d3 blob - 096170bf26e50a683343abc89d28a52a9c947a30 blob + e3a91a1a6869645166bae19987943dd890ca3b7b --- 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) { + arlen = (int)(checkpoint - start); + if (arlen <= 0) { + arlen = (int)(ncheckpoint - start); + checkpoint = ncheckpoint; + } osmtpd_filter_dataline(ctx, "%s%.*s", first ? "" : "\t", - (int)((checkpoint == start ? - ncheckpoint : checkpoint) - start), start); + arlen, start); start = osmtpd_ltok_skip_cfws(checkpoint, 1); + if (*start == '\0') + return; scan = start; arlen = 8; first = 0;