[Pcsclite-muscle] Valgrind error in SCardEstablishContext(): socketcall.connect points to uninitialized bytes

Ludovic Rousseau ludovic.rousseau at gmail.com
Mon Jul 31 08:03:27 UTC 2017


2017-07-19 15:14 GMT+02:00 Thomas Bajer <thomas.bajer at physec.de>:

> Hello,
>

Hello,


>
> I would like to report an error message which valgrind throws the first
> time "SCardEstablishContext()" is called. The error message does not
> appear again when a second call to the function is done.
>
> Please have a look at the attached minimal example code. The program
> connects and disconnects to a smartcard two times. In order for the
> valgrind message to trigger, a smartcard has to be connected to the PC
> and the pcscd service has to be running.
>
> The code was linked with the newest stable release, 1.8.22.
> The code is compiled and linked on a FreeBSD system running FreeBSD 10.3
> (AMD64), the executable is then copied to a pfsense Box which also runs
> FreeBSD 10.3 with the same pcscd version.
>
> It would be great if a developer could look at this and commit a fix for
> this message.
>
> Below is the exampleConnect.c example, the build command and the
> valgrind error log.
>

I can't reproduce your problem with a Debian stable system on amd64.
I get:
$ valgrind --leak-check=full ./sample
==4086== Memcheck, a memory error detector
==4086== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.
==4086== Using Valgrind-3.12.0.SVN and LibVEX; rerun with -h for copyright
info
==4086== Command: ./sample
==4086==
Establish context
List readers
Connect to card
Smartcard connected!
Disconnect card...
Free reader...
Release context...
Establish context
List readers
Connect to card
Smartcard connected!
Disconnect card...
Free reader...
Release context...
DONE!
==4086==
==4086== HEAP SUMMARY:
==4086==     in use at exit: 112 bytes in 4 blocks
==4086==   total heap usage: 21 allocs, 17 frees, 1,922 bytes allocated
==4086==
==4086== LEAK SUMMARY:
==4086==    definitely lost: 0 bytes in 0 blocks
==4086==    indirectly lost: 0 bytes in 0 blocks
==4086==      possibly lost: 0 bytes in 0 blocks
==4086==    still reachable: 112 bytes in 4 blocks
==4086==         suppressed: 0 bytes in 0 blocks
==4086== Reachable blocks (those to which a pointer was found) are not
shown.
==4086== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==4086==
==4086== For counts of detected and suppressed errors, rerun with: -v
==4086== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)


Please rebuild pcsc-lite using this patch and try again:
--- /tmp/lJqSB4_winscard_msg.c  2017-07-31 10:02:24.804416987 +0200
+++ src/winscard_msg.c  2017-07-31 09:59:09.565876305 +0200
@@ -130,6 +130,7 @@ INTERNAL int ClientSetupSession(uint32_t
    *pdwClientID = ret;

    socketName = getSocketName();
+   memset(&svc_addr, 0, sizeof svc_addr);
    svc_addr.sun_family = AF_UNIX;
    strncpy(svc_addr.sun_path, socketName, sizeof(svc_addr.sun_path));

Bye

-- 
 Dr. Ludovic Rousseau
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.alioth.debian.org/pipermail/pcsclite-muscle/attachments/20170731/adc3ca70/attachment.html>


More information about the Pcsclite-muscle mailing list