Re: [PATCH v1] imap/auth_cram.c: Don't use strfcpy() where we don't want to generate a C string

"Kevin J. McCarthy" <[email protected]>
Newsgroups gmane.mail.mutt.devel
Message-ID <aeYaxvETFV47hLIE@qinghai>
Hi Alex,

On Mon, Apr 20, 2026 at 12:02:11PM +0200, Alejandro Colomar via Mutt-dev wrote:
>I think this is correct:

I think it is too.  I'm short on time tonight, but tomorrow I will 
commit my patch to stable and merge it to master.  Then we can take a 
look at your patch to master when it's ready.

I think with your patch the only change I would make is below.

>	diff --git i/imap/auth_cram.c w/imap/auth_cram.c
>	index 9844f444..b42eacb1 100644
>	--- i/imap/auth_cram.c
>	+++ w/imap/auth_cram.c
>	@@ -135,8 +135,8 @@ static void hmac_md5(const char *password, char *challenge,
>			      unsigned char *response)
>	 {
>	   struct md5_ctx ctx;
>	+  char secret[MD5_BLOCK_LEN];
>	   unsigned char ipad[MD5_BLOCK_LEN], opad[MD5_BLOCK_LEN];
>	-  unsigned char secret[MD5_BLOCK_LEN+1];
>	   unsigned char hash_passwd[MD5_DIGEST_LEN];
>	   size_t secret_len, chal_len;
>	   int i;
>	@@ -149,16 +149,15 @@ static void hmac_md5(const char *password, char *challenge,
>	   if (secret_len > MD5_BLOCK_LEN)
>	   {
>	     md5_buffer(password, secret_len, hash_passwd);
>	+    memset(secret, 0, sizeof(secret));
>	     memcpy(secret, hash_passwd, MD5_DIGEST_LEN);
>	     secret_len = MD5_DIGEST_LEN;

We also don't need to set secret_len for the digest anymore, since
you've removed its usage below:

>	   }
>	   else
>	-    strfcpy((char *) secret, password, sizeof(secret));
>	+    strncpy(secret, password, sizeof(secret));
>	
>	-  memset(ipad, 0, sizeof(ipad));
>	-  memset(opad, 0, sizeof(opad));
>	-  memcpy(ipad, secret, secret_len);
>	-  memcpy(opad, secret, secret_len);
>	+  memcpy(ipad, secret, sizeof(ipad));
>	+  memcpy(opad, secret, sizeof(opad));
>	
>	   for (i = 0; i < MD5_BLOCK_LEN; i++)
>	   {
>
>I'll think a bit more about it later, and will send it as a patch.

Thanks Alex!

-- 
Kevin J. McCarthy
GPG Fingerprint: 8975 A9B3 3AA3 7910 385C  5308 ADEF 7684 8031 6BDA
signature.asc (application/pgp-signature, 833 B)
-----BEGIN PGP SIGNATURE-----

iQIzBAEBCgAdFiEEiXWpszqjeRA4XFMIre92hIAxa9oFAmnmGsYACgkQre92hIAx
a9oa2RAA1y1KW4+2gsGUq0xxhsc+DTZlR/GLZIoErW30e/p9xvOl5iV51J2MasxE
f1M/EXJCeNnG5x+FD35MUldltrCJHUzmeAzn//yvMeBEYrC0Q+HwsiVtFecs9GEW
iHWsX405ucbvDInn5YRTjfUceTMthkwXG2Ygd63B96iPrvx+D2Aiv6mhMUkpcYr7
IxvDsWtxl4N/5dpN58q3iuadFfheLFX1X8zBqzZqVCQIjwMoj0nfoW2BvwgwzfCt
i11S+ryq3jgFdH9a3o7V5HD/3EopLoOjZf8fJjOJFGQtOM9X1upvj0k+/fFoI67/
wudVB7tIa3aJJOcNKiQ3bl8P81CL6p/C37Rl2VXRbW1nrWp1vj3DuHXS/qr4YQLf
MsiOogoVWVOWg7Cox0lQOBagnDcvFHZ25i6MIt7vODvMV8Haf7iE2a2loLW9prwI
UCu8IORfkMoa/V2TrVNX99t8cXdsIs40yrXntNDsIG6HvWKmFcWL8IJS3kBGyPTq
joAkdojFTXKf7hYxeS3hEjbCTXC0nU5NfX5y2fP4bDm/87PeOEyYPSdRiAloUWku
KdCUbTode6TC893cAMUICmy3P5Kz4m78ILiXQ8GUcWOC+Z+yskDBhUsFuTCRs3yY
Lgpt4rlUpayYBBIx43NljOGqFVbbwfJ0xd2NbIZEEAsBdduQnJ4=
=Qlwt
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.