crypt32: CryptBinaryToString* must not fill pszString when NULL New

Revisions: 

Revision 1

user image toni Author
14 Aug. 17

CryptBinaryToString must just calculate the expected size when the output buffer is NULL.

When the pszString is written to but is NULL applications will crash.

This patch modifies BinaryToBase64A and BinaryToBase64W that actually perform the work for CryptBinaryToString[AW]

see https://msdn.microsoft.com/en-us/library/windows/desktop/aa379887(v=vs.85).aspx for specs

user image Michael Müller
23 Aug. 17

Any news regarding an updated patch for the development version?

user image toni Author
23 Aug. 17

Haven't had the time to work on it yet. It's pretty trivial so I don't mind if someone wants to pick it up, otherwise I'll do it as soon as I can. I would withdraw the patch here for now but don't have the option.

Single files Merged diff Tar archive
You have unsaved changes. Press CTRL + ENTER in a text field to submit your comments.

0001-crypt32-CryptBinaryToString-must-not-fill-pszString.patch (3 comments)

From ee0a456b8b80d00a9b12bd7dce0d90bf87dece48 Mon Sep 17 00:00:00 2001
From: Tonix <eldrad@autistici.org>
user image Michael Müller
15 Aug. 17

Wine wants people to use their real names for contributions (see https://wiki.winehq.org/Submitting_Patches#Check_your_Git_setup). Could you please attach a new version with the correct author information (Submit new version button at the top)?

user image toni Author
15 Aug. 17

Sure, anyways since the patch is pretty much trivial and afaik not blocker for any application I was thinking to add tests and try submitting directly to wine. Do you think it looks ok?

user image Michael Müller
15 Aug. 17

Looks good. I think you can directly send it upstream. Adding a test would be even better.

Date: Mon, 14 Aug 2017 13:05:23 +0200
Subject: crypt32: CryptBinaryToString must not fill pszString when NULL.
CryptBinaryToString just fills the expected size when the output buffer is NULL.
---
dlls/crypt32/base64.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/dlls/crypt32/base64.c b/dlls/crypt32/base64.c
index 4a904d4..8eaaaa9 100644
--- a/dlls/crypt32/base64.c
+++ b/dlls/crypt32/base64.c
@@ -215,7 +215,7 @@ static BOOL BinaryToBase64A(const BYTE *pbBinary,
charsNeeded += strlen(header) + strlen(sep);
if (trailer)
charsNeeded += strlen(trailer) + strlen(sep);
- if (charsNeeded <= *pcchString)
+ if (pszString && charsNeeded <= *pcchString)
{
LPSTR ptr = pszString;
DWORD size = charsNeeded;
@@ -409,7 +409,7 @@ static BOOL BinaryToBase64W(const BYTE *pbBinary,
charsNeeded += strlenW(header) + strlenW(sep);
if (trailer)
charsNeeded += strlenW(trailer) + strlenW(sep);
- if (charsNeeded <= *pcchString)
+ if (pszString && charsNeeded <= *pcchString)
{
LPWSTR ptr = pszString;
DWORD size = charsNeeded;
--
2.9.3