apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mladen Turk" <mt...@mappingsoft.com>
Subject RE: [PATCH] apr_generate_random_bytes - WIN32
Date Tue, 30 Oct 2001 06:03:56 GMT


> -----Original Message-----
> From: Cliff Woolley [mailto:cliffwoolley@yahoo.com]
> Sent: Monday, October 29, 2001 9:21 PM
> To: Mladen Turk
> Cc: Sander Striker; APR Dev List
> Subject: RE: [PATCH] apr_generate_random_bytes - WIN32
>
> Shouldn't there be an "else" in here that returns apr_get_os_error() if
> GetLastError() returned something OTHER than NTE_BAD_KEYSET?  That makes
> it a little funky to break out of the success case, though.  Seems like it
> should be something like this:
>
>  1    if (!CryptAcquireContext(&hProv,NULL,NULL,PROV_RSA_FULL,0)) {
>  2        /* Try to create the new key container */
>  3        if ((GetLastError() != NTE_BAD_KEYSET) ||
>  4            (!CryptAcquireContext(&hProv,NULL,NULL,PROV_RSA_FULL,
>  5                                  CRYPT_NEWKEYSET))) {
>  6        	return apr_get_os_error();
>  7        }
>  8    }
>
> Note in particular line 3.  We want to call apr_get_os_error() if _either_
> the last error was not NTE_BAD_KEYSET _or_ the CRYPT_NEWKEYSET thingy
> failed.
>
> Is that right?

Well, It is, but I intentionally put the && to be sure not to call the
CryptAcquireContex that will surely fall in case if the last error wasn't
NTE_BAD_KEYSET.
The proper code would be as follows:

1    if (!CryptAcquireContext(&hProv,NULL,NULL,PROV_RSA_FULL,0)) {
2        /* Try to create the new key container */
3        if (GetLastError() == NTE_BAD_KEYSET) {
4            if (!CryptAcquireContext(&hProv,NULL,NULL,PROV_RSA_FULL,
5                                  CRYPT_NEWKEYSET))
6        	return apr_get_os_error();
7        }
8        else
9        	return apr_get_os_error();
10    }


MT.


Mime
View raw message