Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkcs15-init --create-pkcs15 --no-so-pin -> segfault (EXC_BAD_ACCESS) #934

Closed
minfrin opened this issue Jan 3, 2017 · 3 comments · Fixed by #937
Closed

pkcs15-init --create-pkcs15 --no-so-pin -> segfault (EXC_BAD_ACCESS) #934

minfrin opened this issue Jan 3, 2017 · 3 comments · Fixed by #937

Comments

@minfrin
Copy link

minfrin commented Jan 3, 2017

Expected behaviour

What should happen?

Following command runs successfully, or reports a sensible error message:

pkcs15-init --create-pkcs15 --no-so-pin

Actual behaviour

What happens instead?

Little-Net:OpenSC minfrin$ lldb -- pkcs15-init --create-pkcs15 --no-so-pin
(lldb) target create "pkcs15-init"
Current executable set to 'pkcs15-init' (x86_64).
(lldb) settings set -- target.run-args "--create-pkcs15" "--no-so-pin"
(lldb) run
Process 62920 launched: '/usr/local/bin/pkcs15-init' (x86_64)
Using reader with a card: ACS ACR 38U-CCID
Process 62920 stopped

  • thread Added ePass2003. #1: tid = 0x2393a, 0x0000000100001e34 pkcs15-initdo_init_app + 980, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x0) frame #0: 0x0000000100001e34 pkcs15-initdo_init_app + 980
    pkcs15-init`do_init_app:
    -> 0x100001e34 <+980>: movq (%rax), %rdi
    0x100001e37 <+983>: callq 0x100128a6e ; symbol stub for: sc_lock
    0x100001e3c <+988>: movl %eax, -0x30c(%rbp)
    0x100001e42 <+994>: cmpl $0x0, -0x30c(%rbp)

Steps to reproduce

  1. Build latest git master on MacOSX
  2. Run "pkcs15-init --create-pkcs15 --no-so-pin"
  3. Crash

Logs

Little-Net:OpenSC minfrin$ opensc-tool -n
Using reader with a card: ACS ACR 38U-CCID
entersafe

@minfrin
Copy link
Author

minfrin commented Jan 3, 2017

Dropping the --no-so-pin option also causes a crash:

Little-Net:OpenSC minfrin$ lldb -- pkcs15-init --create-pkcs15
(lldb) target create "pkcs15-init"
Current executable set to 'pkcs15-init' (x86_64).
(lldb) settings set -- target.run-args  "--create-pkcs15"
(lldb) run
Process 62947 launched: '/usr/local/bin/pkcs15-init' (x86_64)
Using reader with a card: ACS ACR 38U-CCID
New User PIN.
Please enter User PIN: 
Please type again to verify: 
Unblock Code for New User PIN (Optional - press return for no PIN).
Please enter User unblocking PIN (PUK): 
Please type again to verify: 
Process 62947 stopped
* thread #1: tid = 0x24881, 0x0000000100001e34 pkcs15-init`do_init_app + 980, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
frame #0: 0x0000000100001e34 pkcs15-init`do_init_app + 980
pkcs15-init`do_init_app:
->  0x100001e34 <+980>: movq   (%rax), %rdi
0x100001e37 <+983>: callq  0x100128a6e               ; symbol stub for: sc_lock
0x100001e3c <+988>: movl   %eax, -0x30c(%rbp)
0x100001e42 <+994>: cmpl   $0x0, -0x30c(%rbp)

``

@minfrin
Copy link
Author

minfrin commented Jan 3, 2017

If I'm reading this correctly from the asm p12card is NULL:

    r = sc_lock(p15card->card);
    if (r < 0)
            return r;
    r = sc_pkcs15init_add_app(card, profile, &args);
    sc_unlock(p15card->card);
    return r;

From lldb:

(lldb) print p15card
(void *) $0 = 0x0000000000000000

frankmorgner added a commit to frankmorgner/OpenSC that referenced this issue Jan 5, 2017
regression introduced in de7aaa4

fixes OpenSC#934
closes OpenSC#935
@frankmorgner
Copy link
Member

please check if #937 fixes the problem, thanks

frankmorgner added a commit that referenced this issue Jan 10, 2017
regression introduced in de7aaa4

fixes #934
closes #935
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants