Commit 159c8af5 authored by Juan Lang's avatar Juan Lang Committed by Alexandre Julliard

crypt32: Use consistent error checking.

parent 644dedb7
...@@ -549,10 +549,10 @@ static void CRYPT_KeynameKeeperFromTokenW(struct KeynameKeeper *keeper, ...@@ -549,10 +549,10 @@ static void CRYPT_KeynameKeeperFromTokenW(struct KeynameKeeper *keeper,
TRACE("Keyname is %s\n", debugstr_w(keeper->keyName)); TRACE("Keyname is %s\n", debugstr_w(keeper->keyName));
} }
static DWORD CRYPT_GetNextKeyW(LPCWSTR str, struct X500TokenW *token, static BOOL CRYPT_GetNextKeyW(LPCWSTR str, struct X500TokenW *token,
LPCWSTR *ppszError) LPCWSTR *ppszError)
{ {
DWORD ret = ERROR_SUCCESS; BOOL ret = TRUE;
while (*str && isspaceW(*str)) while (*str && isspaceW(*str))
str++; str++;
...@@ -568,7 +568,8 @@ static DWORD CRYPT_GetNextKeyW(LPCWSTR str, struct X500TokenW *token, ...@@ -568,7 +568,8 @@ static DWORD CRYPT_GetNextKeyW(LPCWSTR str, struct X500TokenW *token,
TRACE("missing equals char at %s\n", debugstr_w(token->start)); TRACE("missing equals char at %s\n", debugstr_w(token->start));
if (ppszError) if (ppszError)
*ppszError = token->start; *ppszError = token->start;
ret = CRYPT_E_INVALID_X500_STRING; SetLastError(CRYPT_E_INVALID_X500_STRING);
ret = FALSE;
} }
} }
else else
...@@ -577,10 +578,10 @@ static DWORD CRYPT_GetNextKeyW(LPCWSTR str, struct X500TokenW *token, ...@@ -577,10 +578,10 @@ static DWORD CRYPT_GetNextKeyW(LPCWSTR str, struct X500TokenW *token,
} }
/* Assumes separators are characters in the 0-255 range */ /* Assumes separators are characters in the 0-255 range */
static DWORD CRYPT_GetNextValueW(LPCWSTR str, DWORD dwFlags, LPCWSTR separators, static BOOL CRYPT_GetNextValueW(LPCWSTR str, DWORD dwFlags, LPCWSTR separators,
struct X500TokenW *token, LPCWSTR *ppszError) struct X500TokenW *token, LPCWSTR *ppszError)
{ {
DWORD ret = ERROR_SUCCESS; BOOL ret = TRUE;
TRACE("(%s, %s, %p, %p)\n", debugstr_w(str), debugstr_w(separators), token, TRACE("(%s, %s, %p, %p)\n", debugstr_w(str), debugstr_w(separators), token,
ppszError); ppszError);
...@@ -594,7 +595,7 @@ static DWORD CRYPT_GetNextValueW(LPCWSTR str, DWORD dwFlags, LPCWSTR separators, ...@@ -594,7 +595,7 @@ static DWORD CRYPT_GetNextValueW(LPCWSTR str, DWORD dwFlags, LPCWSTR separators,
{ {
token->end = NULL; token->end = NULL;
str++; str++;
while (!token->end && !ret) while (!token->end && ret)
{ {
while (*str && *str != '"') while (*str && *str != '"')
str++; str++;
...@@ -610,7 +611,8 @@ static DWORD CRYPT_GetNextValueW(LPCWSTR str, DWORD dwFlags, LPCWSTR separators, ...@@ -610,7 +611,8 @@ static DWORD CRYPT_GetNextValueW(LPCWSTR str, DWORD dwFlags, LPCWSTR separators,
TRACE("unterminated quote at %s\n", debugstr_w(str)); TRACE("unterminated quote at %s\n", debugstr_w(str));
if (ppszError) if (ppszError)
*ppszError = str; *ppszError = str;
ret = CRYPT_E_INVALID_X500_STRING; SetLastError(CRYPT_E_INVALID_X500_STRING);
ret = FALSE;
} }
} }
} }
...@@ -630,7 +632,8 @@ static DWORD CRYPT_GetNextValueW(LPCWSTR str, DWORD dwFlags, LPCWSTR separators, ...@@ -630,7 +632,8 @@ static DWORD CRYPT_GetNextValueW(LPCWSTR str, DWORD dwFlags, LPCWSTR separators,
TRACE("missing value at %s\n", debugstr_w(str)); TRACE("missing value at %s\n", debugstr_w(str));
if (ppszError) if (ppszError)
*ppszError = str; *ppszError = str;
ret = CRYPT_E_INVALID_X500_STRING; SetLastError(CRYPT_E_INVALID_X500_STRING);
ret = FALSE;
} }
return ret; return ret;
} }
...@@ -765,7 +768,7 @@ BOOL WINAPI CertStrToNameW(DWORD dwCertEncodingType, LPCWSTR pszX500, ...@@ -765,7 +768,7 @@ BOOL WINAPI CertStrToNameW(DWORD dwCertEncodingType, LPCWSTR pszX500,
CERT_NAME_INFO info = { 0, NULL }; CERT_NAME_INFO info = { 0, NULL };
LPCWSTR str; LPCWSTR str;
struct KeynameKeeper keeper; struct KeynameKeeper keeper;
DWORD i, error = ERROR_SUCCESS; DWORD i;
BOOL ret = TRUE; BOOL ret = TRUE;
TRACE("(%08x, %s, %08x, %p, %p, %p, %p)\n", dwCertEncodingType, TRACE("(%08x, %s, %08x, %p, %p, %p, %p)\n", dwCertEncodingType,
...@@ -774,12 +777,12 @@ BOOL WINAPI CertStrToNameW(DWORD dwCertEncodingType, LPCWSTR pszX500, ...@@ -774,12 +777,12 @@ BOOL WINAPI CertStrToNameW(DWORD dwCertEncodingType, LPCWSTR pszX500,
CRYPT_InitializeKeynameKeeper(&keeper); CRYPT_InitializeKeynameKeeper(&keeper);
str = pszX500; str = pszX500;
while (str && *str && !error && ret) while (str && *str && ret)
{ {
struct X500TokenW token; struct X500TokenW token;
error = CRYPT_GetNextKeyW(str, &token, ppszError); ret = CRYPT_GetNextKeyW(str, &token, ppszError);
if (!error && token.start) if (ret && token.start)
{ {
PCCRYPT_OID_INFO keyOID; PCCRYPT_OID_INFO keyOID;
...@@ -790,7 +793,8 @@ BOOL WINAPI CertStrToNameW(DWORD dwCertEncodingType, LPCWSTR pszX500, ...@@ -790,7 +793,8 @@ BOOL WINAPI CertStrToNameW(DWORD dwCertEncodingType, LPCWSTR pszX500,
{ {
if (ppszError) if (ppszError)
*ppszError = token.start; *ppszError = token.start;
error = CRYPT_E_INVALID_X500_STRING; SetLastError(CRYPT_E_INVALID_X500_STRING);
ret = FALSE;
} }
else else
{ {
...@@ -801,7 +805,8 @@ BOOL WINAPI CertStrToNameW(DWORD dwCertEncodingType, LPCWSTR pszX500, ...@@ -801,7 +805,8 @@ BOOL WINAPI CertStrToNameW(DWORD dwCertEncodingType, LPCWSTR pszX500,
{ {
if (ppszError) if (ppszError)
*ppszError = str; *ppszError = str;
error = CRYPT_E_INVALID_X500_STRING; SetLastError(CRYPT_E_INVALID_X500_STRING);
ret = FALSE;
} }
else else
{ {
...@@ -820,9 +825,9 @@ BOOL WINAPI CertStrToNameW(DWORD dwCertEncodingType, LPCWSTR pszX500, ...@@ -820,9 +825,9 @@ BOOL WINAPI CertStrToNameW(DWORD dwCertEncodingType, LPCWSTR pszX500,
sep = crlfSep; sep = crlfSep;
else else
sep = allSeps; sep = allSeps;
error = CRYPT_GetNextValueW(str, dwStrType, sep, &token, ret = CRYPT_GetNextValueW(str, dwStrType, sep, &token,
ppszError); ppszError);
if (!error) if (ret)
{ {
str = token.end; str = token.end;
ret = CRYPT_ValueToRDN(dwCertEncodingType, &info, ret = CRYPT_ValueToRDN(dwCertEncodingType, &info,
...@@ -833,18 +838,13 @@ BOOL WINAPI CertStrToNameW(DWORD dwCertEncodingType, LPCWSTR pszX500, ...@@ -833,18 +838,13 @@ BOOL WINAPI CertStrToNameW(DWORD dwCertEncodingType, LPCWSTR pszX500,
} }
} }
CRYPT_FreeKeynameKeeper(&keeper); CRYPT_FreeKeynameKeeper(&keeper);
if (!error) if (ret)
{ {
if (ppszError) if (ppszError)
*ppszError = NULL; *ppszError = NULL;
ret = CryptEncodeObjectEx(dwCertEncodingType, X509_NAME, &info, ret = CryptEncodeObjectEx(dwCertEncodingType, X509_NAME, &info,
0, NULL, pbEncoded, pcbEncoded); 0, NULL, pbEncoded, pcbEncoded);
} }
else
{
SetLastError(error);
ret = FALSE;
}
for (i = 0; i < info.cRDN; i++) for (i = 0; i < info.cRDN; i++)
{ {
DWORD j; DWORD j;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment