Ticket #125 (new enhancement)

Opened 2 years ago

Patch: PKCS15 emulation lacks a custom 'clear' function

Reported by: harningt Owned by: opensc-devel@…
Priority: high Milestone: 0.11.5
Component: opensc Version: 0.11.1
Severity: major Keywords:
Cc:

Description

The PKCS15 library lacks a 'clear' function for sc_pkcs15_card_t. This is necessary for emulated cards especially in the case of Windows deployment.

Example of badness w/o the 'clear' function:

  • emulation initializes
    • label = strdup("label") -- Inside emulated dll
  • sc_pkcs15_free/clear
    • if(p15card->label) free(p15card->label)

W/ the emulation DLL, the C library could be different, thus strdup could use a different allocation method than free especially in the case of MSVCRT debug/release... or different versions.

Attached is a patch which adds:

  • void (*clear)(struct sc_pkcs15_card*) to sc_pkcs15_card
  • if(p15card->clear) p15card->clear(p15card); to sc_..p15card..free/clear

Note: I would have used free, but since a clear function exists to reuse the p15card structure, I figured clear was more appropriate so the implementor of that function knows to NULL out pointers. It's also important to NULL out pointers, especially in the case of free-ing labels and other structures that would otherwise be freed by OpenSC.

Note as to why the severity:

If any external p15 plugins are created, this can cause problems for working in Windows, or any environment where the C libraries can clash. It also allows for custom allocation functions w/ p15card data.

Attachments

pkcs15-cleanup-func.patch (1.0 kB) - added by harningt 2 years ago.

Change History

Changed 2 years ago by harningt

Note: See TracTickets for help on using tickets.