Re: [PATCH] Fix IMAP auth_crm MD5 digest of secret to use memcpy().
Alejandro Colomar via Mutt-dev <[email protected]>
| Newsgroups | gmane.mail.mutt.devel |
|---|---|
| Message-ID | <aeUUCrWoPYRTRVOQ@devuan> |
Hi Rene, On 2026-04-19T17:08:29+0200, Rene Kita wrote: > On Sun, Apr 19, 2026 at 01:50:51PM +0800, Kevin J. McCarthy wrote: > > For a secret longer that MD5_BLOCK_LEN, an MD5 digest is used > > s/that/than > > > instead. However, mutt was incorrectly using strfcpy() on the raw > > binary value returned by md5_buffer, instead of memcpy(). This could > > result in authentication failing. > > > > This likely hasn't been a big issue because: > > 1. CRAM-MD5 is not used much anymore > > 2. Most people likely don't have a password length greater than 64 > > bytes. > > 3. It relies on the case of an exactly aligned 0x00 byte in the digest > > result, which is likely also infrequent. > > > > Thanks to [email protected] for the security report. > > --- > > This is 5 in the list evilrabbit sent. > > > > imap/auth_cram.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/imap/auth_cram.c b/imap/auth_cram.c > > index 6080ea47..6a265de6 100644 > > --- a/imap/auth_cram.c > > +++ b/imap/auth_cram.c > > @@ -149,7 +149,7 @@ static void hmac_md5 (const char* password, char* challenge, > > if (secret_len > MD5_BLOCK_LEN) > > { > > md5_buffer (password, secret_len, hash_passwd); > > - strfcpy ((char*) secret, (char*) hash_passwd, MD5_DIGEST_LEN); > > + memcpy(secret, hash_passwd, MD5_DIGEST_LEN); > > secret_len = MD5_DIGEST_LEN; > > } > > else > > The part after the else above is: > strfcpy((char *) secret, password, sizeof(secret)); > > Are we dealing here with strings or with buffers of bytes/chars? Buffers of bytes. > If we > need strings, that is nul-terminated char buffers, the memcpy above will > not ensure it, right? If we are not dealing with strings we shouldn't > use str-functions here to avoid confusing people like me. ;-) Agree. We should at least do it in the master branch. > From my little understanding of the code I would suggest to use memcpy > but also replace the strfcpy in the else clause. Agree. Have a lovely day! Alex -- <https://www.alejandro-colomar.es>
signature.asc
(application/pgp-signature, 833 B)
-----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEES7Jt9u9GbmlWADAi64mZXMKQwqkFAmnlFNoACgkQ64mZXMKQ wqlGqxAAkstw+iyvIq9r/Q/a5NQrZzJJcQWHDIYrQJBlriBn0gIph9GUCbKRRKRD TIpdRMOj7jFTw9x9I8FGPPpSep2bd9L34na+w/VeYF7ziKf7x/NIk6gxqY0AE3MV NNiLKzGOIR8NOhruq4g49NgwRHobOhFOz+c2r85cU9T5M/f9R+i0lgAMlHtd5khn 8hQz1pvUSdggESwiqpAzVZFQ/ZMzLbRQs/jJaFTn4Vt5kIKi/2lbuar95y8cUP81 5t1M/QJdt5VkYjCvj3MNmXus/GyaZcaZy4p+IfhYC51ktEvD0OrJBZk+zyP7cdGo MIyUU5PpVEQwmj2onKZ8kfqHqGxzxbd9MB0OIRqnlQLHpLvG0JWz1mJP6yE4q5SM rcSBsqgz+ePkmCunw2ysdv8BJog/trKI8jf2Pp5ixX52YwWTDyjLQL7CvqJHwQMf w6+iTs89f6ZoLtW8dO/D5D/j+ehOYE3LgG+p32T3VxSuWdyIGqmu7WHdD8uS39tP NQbKHxhUz9zrUvhQ2P3JaCI6GRM8SHHcWbkqa9ZqBGp7S/7Mt0QV03K3cEsm5Gg3 cngYTmKlcgY9Rj0OfZ/p0UL3euJJ9tmh31by2yZGff7OmCan+CMnZ3ax/9g74fae mFrqH11pHfpsNYW0DxfOZtMW/JIVqv5U5IjA//nv6rSXkxlAx2c= =POcu -----END PGP SIGNATURE-----