Page MenuHome GnuPG

scdaemon is not working in cygwin (64bit)
Closed, ResolvedPublic

Description

Hello!

Trying to access my gnuk using gpg in cygwin, I've discovered a rare bug. Here is an fragment from scdaemon.log:

2019-04-03 20:28:24 scdaemon[1606.600048ae0] DBG: send apdu: c=00 i=A4 p1=00 p2=0C lc=2 le=-1 em=0
2019-04-03 20:28:24 scdaemon[1606.600048ae0] DBG:   PCSC_data: 00 A4 00 0C 02 3F 00
2019-04-03 20:28:24 scdaemon[1606.600048ae0] pcsc_transmit failed: invalid parameter (0x80100004)

At the same time, the "native" ɡpɡ which comes with standard gpg4win installation worked fine. After some discovery I've found out that the reason is a wrong memory layout for SCardTransmit 2nd argument (a pointer to SCARD_IO_REQUEST). It is defined in apdu.c like this:

struct pcsc_io_request_s
{
  unsigned long protocol;
  unsigned long pci_len;
};

but in WinAPI reference it is defined asː

typedef struct {
  DWORD dwProtocol;
  DWORD cbPciLength;
} SCARD_IO_REQUEST;

When compiled for 64-bit, unsigned long occupies 8 bytes, whereas DWORD size is 4 bytes regardless of used memory model. I've changed unsigned long to pcsc_dword_t and problem disappeared. Here is the patchː

Revisions and Commits

Event Timeline

j0t updated the task description. (Show Details)
werner triaged this task as Normal priority.Apr 9 2019, 8:54 AM
werner added a project: patch.
werner added a subscriber: werner.

We do not support 64 bit Windows thus this problem on Cygwin is obvious. Funny that Cygwin falls back to native Windows object in this case.

gniibe added a subscriber: gniibe.

For future, it would make sense applying your patch, but I wonder if it works on macOS.
Let me check.

In master, I pushed a change, closing.