Fix stack overflow with X509Certificate FriendlyName
authorKevin Jones <kevin@vcsjones.com>
Thu, 6 Jan 2022 21:15:18 +0000 (16:15 -0500)
committerGitHub <noreply@github.com>
Thu, 6 Jan 2022 21:15:18 +0000 (13:15 -0800)
commitd988a524d2dcc185677f195d491de99a6f5e74db
treeb88bde67e089d09e08da43ef0cc4ac20c43a94b1
parent392b35ceee057d91f752c91e38d42846814ab64e
Fix stack overflow with X509Certificate FriendlyName

A FriendlyName in Windows' length is a DWORD, an unsigned integer. We
however marshal it as a signed integer, so a friendly name with a
length greater than int.MaxValue would wrap around to negative. This
in turn would be "below" the stackalloc threshold, and attempt to stackalloc
a negative value. stackalloc treats this value as unsigned, so it results
in allocating too much on the stack.
src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CertGetCertificateContextPropertyString.cs
src/libraries/System.Security.Cryptography.X509Certificates/src/Internal/Cryptography/Pal.Windows/CertificatePal.cs