apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Cliff Woolley <cliffwool...@yahoo.com>
Subject RE: [PATCH] apr_generate_random_bytes - WIN32
Date Mon, 29 Oct 2001 20:20:40 GMT
On Mon, 29 Oct 2001, Mladen Turk wrote:

> Ooops! It should be:
> if (!CryptAcquireContext(&hProv,NULL,NULL,PROV_RSA_FULL,

I'd wondered about that, too.

> Index: rand.c
> ===================================================================
> RCS file: /home/cvspublic/apr/misc/win32/rand.c,v
> retrieving revision 1.10
> diff -u -r1.10 rand.c
> --- rand.c	2001/02/16 04:15:58	1.10
> +++ rand.c	2001/10/29 19:24:55
> @@ -63,7 +63,12 @@
>      apr_status_t res = APR_SUCCESS;
>
>      if (!CryptAcquireContext(&hProv,NULL,NULL,PROV_RSA_FULL,0)) {
> -	return apr_get_os_error();
> +        /* Try to create the new key container */
> +        if ((GetLastError() == NTE_BAD_KEYSET) &&
> +            !CryptAcquireContext(&hProv,NULL,NULL,PROV_RSA_FULL,
> +                                CRYPT_NEWKEYSET)) {
> +        	return apr_get_os_error();
> +        }
>      }

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?

--Cliff

--------------------------------------------------------------
   Cliff Woolley
   cliffwoolley@yahoo.com
   Charlottesville, VA



Mime
View raw message