[crypt32] CryptProtectData/CryptUnprotectData helper functions

Kees Cook kees at outflux.net
Wed May 18 14:08:35 CDT 2005


On Wed, May 18, 2005 at 07:31:03PM +0200, Alexandre Julliard wrote:
> > +    wine_dbg_printf("%s\n",report);
> 
> You should use wine_dbg_sprintf here and return a string.

Okay.

> > +static
> > +void serialize_dword(DWORD value,BYTE ** ptr)
> > +{
> > +    /*TRACE("called\n");*/
> > +
> > +    *((DWORD*)*ptr)=value;
> > +    *ptr+=sizeof(DWORD);
> 
> This (and other similar things later on) isn't safe for CPUs that
> don't allow unaligned accesses, you have to use memcpy instead.

Ah, whoops.  I will fix these.

> > +    pInfo->info0.pbData=strdup(crypt_magic_str);
> 
> You don't want to use strdup, you should use HeapAlloc and friends
> (especially since you use HeapFree later on).

Is there a HeapAlloc-using version of strdup?  I see a while back 
someone implemented their own in their own code; is there a common batch 
of wine functions, or should I do the same thing?

http://www.winehq.org/hypermail/wine-patches/2004/08/0558.html

StrDup is defined for Windows in .NET and VB, but not for VC, it seems?

> > +crypt_report_func_input(DATA_BLOB* pDataIn,
> > +                        DATA_BLOB* pOptionalEntropy,
> > +                        CRYPTPROTECT_PROMPTSTRUCT* pPromptStruct,
> > +                        DWORD dwFlags)
> > +{
> > +    wine_dbg_printf("\tpPromptStruct: 0x%x\n",(unsigned int)pPromptStruct);

> > +static void
> > +announce_bad_opaque_data()
> > +{
> > +    wine_dbg_printf("CryptUnprotectData received the following pDataIn DATA_BLOB that seems to\n");
> > +    wine_dbg_printf("have NOT been generated by Wine:\n");
> > +}
> 
> You should use the TRACE/FIXME macros here, not raw wine_dbg_printf.

FIXME is sane for the "announce_bad_opaque_data", but I'd still like to
use something that doesn't prefix the hexdumps with the function name
for easier readability in the crypt_report_func_input, since there is
already a TRACE/FIXME call being made prior to it's call.  Is this okay?
 
-- 
Kees Cook                                            @outflux.net



More information about the wine-devel mailing list