Re: Fwd: report 1/3: buffer under-read in rfc2047.c lwslen()
Alejandro Colomar via Mutt-dev <[email protected]> Sun, 21 Jun 2026 18:02:06 +0200
| Newsgroups | gmane.mail.mutt.devel |
|---|---|
| Message-ID | <ajgKhraH1_niGEkY@devuan> |
Hi Vincent,
On 2026-06-21T17:31:38+0200, Vincent Lefevre wrote:
> On 2026-06-20 22:48:38 +0200, Alejandro Colomar via Mutt-dev wrote:
> > Hi Vincent,
> >
> > On 2026-06-20T19:39:29+0200, Vincent Lefevre wrote:
> > > On 2026-06-18 11:28:00 +0800, Kevin J. McCarthy wrote:
> > > > In this case, I think the proposed patch is the best solution:
> > > >
> > > > diff --git a/rfc2047.c b/rfc2047.c
> > > > index d72ae997..2bdd8553 100644
> > > > --- a/rfc2047.c
> > > > +++ b/rfc2047.c
> > > > @@ -815,7 +815,7 @@ static size_t lwslen(const char *s, size_t n)
> > > > len = (size_t)(p - s);
> > > > break;
> > > > }
> > > > - if (strchr("\r\n", *(p-1))) /* LWS doesn't end with CRLF */
> > > > + if (len > 0 && strchr("\r\n", *(p-1))) /* LWS doesn't end with CRLF */
> > > > len = (size_t)0;
> > > > return len;
> > > > }
> > >
> > > "len = (size_t)0;" has a cast, but "len > 0" doesn't.
> > > This doesn't matter much, but this is not consistent.
> >
> > Comparison with a literal should not use casts.
>
> OK here, but why is there a cast for the assignment, then?
>
> If the cast is useless for the comparison, then it should also
> be useless for the assignment.
Agree. I'd remove it. I'd remove most casts in any program, FWIW, and
wrap all the few remaining necessary ones in macros that make them easy
to grep and verify.
In this case, I'd remove the cast in the assignment.
Have a lovely day!
Alex
--
<https://www.alejandro-colomar.es>
signature.asc
(application/pgp-signature, 833 B)
-----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEES7Jt9u9GbmlWADAi64mZXMKQwqkFAmo4Cv0ACgkQ64mZXMKQ wqmQsxAAk+2XdzfRRmJg0PgpZLWYL3+8rY4POzleSDXkW3S7hz2fMgJmZC2zcomC /roXM9cNlSmyRQf6PNEH/8l+Dl1eD8YVylnBq5DCBq1dGuKHT8IbsiASTBlw/TXc vBEUtwdnuo73ZkqOqTzdMzDB26k+Bjm43kcPpna5BUhOu5WzXPlPAujnrPbc7sfT Vhy66IH71GPB++o4T7pbyHe+AeLKuNvDJOe0rwKaSwhgK8o0LlSUQuhlcG1DRXpw sp3eHMHp2Qa9gCSFSs7Rg3SGVVanDuoBQFZU1rfAfPuSB6hmrhF4hm49gtSZHJ1E oDYF2t8xP8aO37dxUK28R3/m9O68zjLKfinFTPy7XBqQU05cYNXZBpVXvlDxC6Qp gUW70qbqtDcnYdaPT3JL6I1mkfpmScnlYAM673ccx0fF/0Q7B/oPv68LAYzWI4h7 eXz2Q6j/llBqq1YykcWRWMiGB3284uqSFJHK7rtfvxG+MoW4EAHGl57XUSa5B8xx ewsEPcWd5dCfs/F6J3ZzAq9OVKPNTXxbWBLZLOcF+KepBVIzJJbn2iPbw/nYMb08 yyy+5SRrIn0lyxp+XOEG7MUhP5oUdveYGBidutmP/ZF+rTlVYJrcoVABlZ5TTQxd nftFrg9SGvLCiCvIyvVLEc2aGpEh7gnx71eY5/hkVH9wZZHre3g= =+v7I -----END PGP SIGNATURE-----