kaoh / globalplatform

C library + command-line for Open- / GlobalPlatform smart cards
https://kaoh.github.io/globalplatform/
Other
72 stars 30 forks source link

Uninitialized variables were causing on macOS Catalina #35

Closed dmercer-google closed 3 years ago

dmercer-google commented 3 years ago

This took me quite a while to figure out. What I was seeing was that when I called OPGP_list_readers prior to calling OPGP_card_connect the variable dummy at line 196 of gppcscconnectionplugin/src/gppcscconnectionplugin.c was being populated with some very large invalid number which was then causing SCardStatus to fail with 0x8010000F, Card protocol mismatch. Initialing dummy to 0 fixed the issue. I then initialized all variables in the file.

Note: I was calling into the code from a Go app. No idea if that had anything to do with it.

macOS Catalina version 10.15.7 go version go1.15.3 darwin/amd64

koh-osug commented 3 years ago

Thank you for finding this. Also other locations in the project are not initializing variables to a default value, but I think in these locations the variables are later assigned to a value and are not evaluated before working on uninitialized memory, I guess which was the case for the dummy variable, although according to the API this actually should not be the case. I'm also wondering why I have named the variable dummy.