diff --git a/ChangeLog b/ChangeLog index 13d591a..7e475fe 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +1.8.25: Ludovic Rousseau +25 March 2019 +- Fix a socket issue when pcscd is used inside LXC container +- pcsc-spy: always provide a total time of execution +- Fix resource leak if SCardEstablishContext() fails +- Fix realloc(3) error handling (possible memory leak) +- Remove usage of function chmod(2) to use fchmod(2) (fix race condition) + + 1.8.24: Ludovic Rousseau 12 October 2018 - the project moved to https://pcsclite.apdu.fr/ diff --git a/ChangeLog.git b/ChangeLog.git index 401e8f6..aa33245 100644 --- a/ChangeLog.git +++ b/ChangeLog.git @@ -1,4 +1,185 @@ -commit 73d95ada3221c060cbd7b6aa2375453f9d0e359b (HEAD -> master, origin/master, origin/HEAD) +commit efc56971cb8f8bf9cb44090bb3851d8c1d2a00f7 (HEAD -> master, tag: pcsc-1.8.25, origin/master, origin/HEAD) +Author: Ludovic Rousseau +Date: Mon Mar 25 20:56:43 2019 +0100 + + Release 1.8.25 + + ChangeLog | 9 +++++++++ + configure.ac | 2 +- + 2 files changed, 10 insertions(+), 1 deletion(-) + +commit d627aee864c3e9ce40e375fcc0e34a7855b6f0f1 (zotac/master, github/master) +Author: Ludovic Rousseau +Date: Sun Mar 24 14:51:41 2019 +0100 + + pcscd.socket.in: explicitly set socket file mode + + Fixes Debian #924914 + Thanks to Mathias Behrle for the patch + + etc/pcscd.socket.in | 1 + + 1 file changed, 1 insertion(+) + +commit b9e6fe054c2ce883ce6070d4a5761d9d1e1da1bc (zmaster) +Author: Ludovic Rousseau +Date: Fri Mar 22 10:39:14 2019 +0100 + + pcsc-spy: always a total time of execution + + Use the latest function return to compute the total execution time. + + Now the total time is always available. If the latest PC/SC command + does not return (because the process has been interrupted) the total + time may be a bit shorter than expected but it is less problematic than + no total tiem at all. + + src/spy/pcsc-spy | 13 ++++++------- + 1 file changed, 6 insertions(+), 7 deletions(-) + +commit 9561e5562d5fb00540589ccb9e4744366ec4b310 +Author: Ludovic Rousseau +Date: Fri Mar 22 10:21:35 2019 +0100 + + pcsc-spy: fix a typo in a comment + + src/spy/pcsc-spy | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +commit e641eaa72530bd8188ff584e33d06bf60a384995 +Author: Ludovic Rousseau +Date: Wed Jan 16 11:03:19 2019 +0100 + + Doc: more explicit documentation for −−auto−exit + + pcscd does not exit after 60 seconds but after 60 seconds of inactivity + after the release of the last PC/SC context. + If you start pcscd with −−auto−exit but do run any PC/SC application + then pcscd will NOT exit after 60 seconds. + + Thanks to Matthias Apitz for the bug report. + + doc/pcscd.8.in | 3 ++- + 1 file changed, 2 insertions(+), 1 deletion(-) + +commit 36c8eae890dc81f0e25ebf0be1c6a969ffd9543a +Author: vegaMato +Date: Tue Dec 18 18:37:22 2018 +0100 + + Remove usage of function chmod(2) to use fchmod(2) + + Race condition possibility; CWE-362: Concurrent Execution using Shared + Resource with Improper Synchronization ('Race Condition') + + Thanks to PA193 project + https://github.com/vegaMato/PCSC-lite-project-tasks + + src/pcscdaemon.c | 5 +++-- + 1 file changed, 3 insertions(+), 2 deletions(-) + +commit 430043842e05a300f1dda1b93fcfa8fceadd81e5 +Author: St4lkerino +Date: Tue Dec 18 19:22:32 2018 +0100 + + Fix realloc(3) error handling + + From realloc(3) manpage: + The realloc() function returns a pointer to the newly allocated memory, + which is suitably aligned for any built-in type and may be different + from ptr, or NULL if the request fails. If size was equal to 0, either + NULL or a pointer suitable to be passed to free() is returned. If + realloc() fails, the original block is left untouched; it is not freed + or moved. + + If realloc() fails then the memory that was previously allocated needs + to be freed, or it will create a memory leak. + + It was not a real problem because if realloc(3) failed then pcscd would + exit immediatly and the memory would not leak for a long time. + + Thanks to PA193 project + https://github.com/vegaMato/PCSC-lite-project-tasks + + src/hotplug_libudev.c | 8 ++++++-- + src/hotplug_libusb.c | 6 ++++-- + 2 files changed, 10 insertions(+), 4 deletions(-) + +commit ad8c6fb98d29ccca5c5ae5287311b845f42853f1 +Author: Ludovic Rousseau +Date: Thu Jan 3 19:11:55 2019 +0100 + + pcscd: update copyright dates returned by --version + + src/pcscdaemon.c | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +commit ea89e0598f86e56d51126addcbab97c4d722cd79 +Author: Ludovic Rousseau +Date: Sat Dec 15 13:43:10 2018 +0100 + + log: on GNU/Linux a pthread_t is unsigned + + Do not log the thread id as a signed integer. + We should not have logs like: + 00000012 [-1211058432] pcscdaemon.c:352:main() Force colored logs + + src/debuglog.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +commit 9d5572b85c1f827e8e7075e34d4c11293188963e +Author: Ludovic Rousseau +Date: Wed Dec 12 17:45:05 2018 +0100 + + .gitignore: ignore doc/api + + .gitignore | 1 + + 1 file changed, 1 insertion(+) + +commit 4e736c11d6414b1bc2cc8cccbde1f784e08e2dd7 +Author: Ludovic Rousseau +Date: Fri Dec 7 09:28:12 2018 +0100 + + Remove 2 outdated comments about card always powered on + + Since "Card auto power on and off" feature as been introduced in 2010 + the card is _not_ always powered. + + Thanks to Jan Parcel for the bug report. + + src/winscard.c | 6 ------ + 1 file changed, 6 deletions(-) + +commit 53ab2bc875d24c80d2069440cf2a9ec95eda892d +Author: Ludovic Rousseau +Date: Mon Nov 26 15:04:55 2018 +0100 + + MSGRemoveContext: remove dead code + + Issue found by Coverity: + >>> CID 1441490: Code maintainability issues (UNUSED_VALUE) + >>> Assigning value "2148532329L" to "rv" here, but that stored value is overwritten before it can be used. + + UnitaryTests/SCardBeginTransaction_SharedMode.py | 2 +- + src/winscard_svc.c | 2 -- + 2 files changed, 1 insertion(+), 3 deletions(-) + +commit dd34cb3695cfee90e4cc8720446b1116ca19e2d0 +Author: Ludovic Rousseau +Date: Thu Nov 15 11:54:31 2018 +0100 + + Fix resource leak if SCardEstablishContext() fails + + When SCardEstablishContext() failed after the connection to the daemon + was made (for example when polkit is used) then the socket to the daemon + was not closed. + + Thanks to MartinN-n for the bug report + "Leaking sockets #50" + https://github.com/LudovicRousseau/PCSC/issues/50 + + src/winscard_clnt.c | 24 ++++++++++++++++++------ + 1 file changed, 18 insertions(+), 6 deletions(-) + +commit 73d95ada3221c060cbd7b6aa2375453f9d0e359b (tag: pcsc-1.8.24) Author: Ludovic Rousseau Date: Fri Oct 12 10:43:51 2018 +0200 @@ -82,7 +263,7 @@ Date: Tue Oct 9 12:10:13 2018 +0200 COPYING | 24 ------------------------ 1 file changed, 24 deletions(-) -commit db6b67acf7027ecbc275cdb8242cddf3e6508b26 (zotac/master, zmaster) +commit db6b67acf7027ecbc275cdb8242cddf3e6508b26 Author: Ludovic Rousseau Date: Mon Oct 8 14:41:53 2018 +0200 diff --git a/Makefile.in b/Makefile.in index 6d07b5e..51a4e02 100644 --- a/Makefile.in +++ b/Makefile.in @@ -164,7 +164,7 @@ DIST_SUBDIRS = $(SUBDIRS) am__DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/config.h.in \ $(top_srcdir)/src/PCSC/pcsclite.h.in AUTHORS COPYING ChangeLog \ INSTALL NEWS README TODO ar-lib compile config.guess \ - config.sub install-sh ltmain.sh missing ylwrap + config.sub depcomp install-sh ltmain.sh missing ylwrap DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) distdir = $(PACKAGE)-$(VERSION) top_distdir = $(distdir) diff --git a/configure b/configure index e036ed4..473ab6e 100755 --- a/configure +++ b/configure @@ -1,6 +1,6 @@ #! /bin/sh # Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.69 for pcsc-lite 1.8.24. +# Generated by GNU Autoconf 2.69 for pcsc-lite 1.8.25. # # # Copyright (C) 1992-1996, 1998-2012 Free Software Foundation, Inc. @@ -587,8 +587,8 @@ MAKEFLAGS= # Identity of this package. PACKAGE_NAME='pcsc-lite' PACKAGE_TARNAME='pcsc-lite' -PACKAGE_VERSION='1.8.24' -PACKAGE_STRING='pcsc-lite 1.8.24' +PACKAGE_VERSION='1.8.25' +PACKAGE_STRING='pcsc-lite 1.8.25' PACKAGE_BUGREPORT='' PACKAGE_URL='' @@ -1392,7 +1392,7 @@ if test "$ac_init_help" = "long"; then # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat <<_ACEOF -\`configure' configures pcsc-lite 1.8.24 to adapt to many kinds of systems. +\`configure' configures pcsc-lite 1.8.25 to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... @@ -1463,7 +1463,7 @@ fi if test -n "$ac_init_help"; then case $ac_init_help in - short | recursive ) echo "Configuration of pcsc-lite 1.8.24:";; + short | recursive ) echo "Configuration of pcsc-lite 1.8.25:";; esac cat <<\_ACEOF @@ -1615,7 +1615,7 @@ fi test -n "$ac_init_help" && exit $ac_status if $ac_init_version; then cat <<\_ACEOF -pcsc-lite configure 1.8.24 +pcsc-lite configure 1.8.25 generated by GNU Autoconf 2.69 Copyright (C) 2012 Free Software Foundation, Inc. @@ -2091,7 +2091,7 @@ cat >config.log <<_ACEOF This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. -It was created by pcsc-lite $as_me 1.8.24, which was +It was created by pcsc-lite $as_me 1.8.25, which was generated by GNU Autoconf 2.69. Invocation command line was $ $0 $@ @@ -2955,7 +2955,7 @@ fi # Define the identity of the package. PACKAGE='pcsc-lite' - VERSION='1.8.24' + VERSION='1.8.25' cat >>confdefs.h <<_ACEOF @@ -16172,7 +16172,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # report actual input values of CONFIG_FILES etc. instead of their # values after options handling. ac_log=" -This file was extended by pcsc-lite $as_me 1.8.24, which was +This file was extended by pcsc-lite $as_me 1.8.25, which was generated by GNU Autoconf 2.69. Invocation command line was CONFIG_FILES = $CONFIG_FILES @@ -16238,7 +16238,7 @@ _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`" ac_cs_version="\\ -pcsc-lite config.status 1.8.24 +pcsc-lite config.status 1.8.25 configured by $0, generated by GNU Autoconf 2.69, with options \\"\$ac_cs_config\\" diff --git a/configure.ac b/configure.ac index 4e6d9bb..0fa5168 100644 --- a/configure.ac +++ b/configure.ac @@ -3,7 +3,7 @@ AC_PREREQ([2.69]) -AC_INIT([pcsc-lite],[1.8.24]) +AC_INIT([pcsc-lite],[1.8.25]) AC_CONFIG_SRCDIR(src/pcscdaemon.c) AM_INIT_AUTOMAKE(1.8 dist-bzip2 no-dist-gzip) AC_CONFIG_HEADERS([config.h]) diff --git a/doc/pcscd.8.in b/doc/pcscd.8.in index ccc5782..81475ba 100644 --- a/doc/pcscd.8.in +++ b/doc/pcscd.8.in @@ -73,7 +73,8 @@ file to detect added or removed non-USB readers (serial or PCMCIA). . .TP .BR \-x ", " \-\-auto\-exit -pcscd will quit after 60 seconds of inactivity. This is used when pcscd +pcscd will quit after 60 seconds of inactivity after the release of +the last PC/SC context. This is used when pcscd os started on demand by systemd. .TP .BR \-S ", " \-\-reader\-name\-no\-serial diff --git a/etc/pcscd.socket.in b/etc/pcscd.socket.in index 6fc93da..0a5654b 100644 --- a/etc/pcscd.socket.in +++ b/etc/pcscd.socket.in @@ -3,6 +3,7 @@ Description=PC/SC Smart Card Daemon Activation Socket [Socket] ListenStream=@ipcdir@/pcscd.comm +SocketMode=0666 [Install] WantedBy=sockets.target diff --git a/src/PCSC/pcsclite.h b/src/PCSC/pcsclite.h index 3c7f615..801c806 100644 --- a/src/PCSC/pcsclite.h +++ b/src/PCSC/pcsclite.h @@ -279,7 +279,7 @@ extern const SCARD_IO_REQUEST g_rgSCardT0Pci, g_rgSCardT1Pci, g_rgSCardRawPci; #define INFINITE 0xFFFFFFFF /**< Infinite timeout */ #endif -#define PCSCLITE_VERSION_NUMBER "1.8.24" /**< Current version */ +#define PCSCLITE_VERSION_NUMBER "1.8.25" /**< Current version */ /** Maximum readers context (a slot is count as a reader) */ #define PCSCLITE_MAX_READERS_CONTEXTS 16 diff --git a/src/debuglog.c b/src/debuglog.c index feb885c..8f55d58 100644 --- a/src/debuglog.c +++ b/src/debuglog.c @@ -190,7 +190,7 @@ static void log_line(const int priority, const char *DebugBuffer) #ifdef __APPLE__ #define THREAD_FORMAT "%p" #else -#define THREAD_FORMAT "%ld" +#define THREAD_FORMAT "%lu" #endif printf("%s%.8d%s [" THREAD_FORMAT "] %s%s%s\n", time_pfx, delta, time_sfx, thread_id, diff --git a/src/hotplug_libudev.c b/src/hotplug_libudev.c index 81c4342..25bd408 100644 --- a/src/hotplug_libudev.c +++ b/src/hotplug_libudev.c @@ -228,15 +228,19 @@ static LONG HPReadBundleValues(void) Log2(PCSC_LOG_INFO, "Increase driverTracker to %d entries", driverSize); #endif - driverTracker = realloc(driverTracker, + + void* tmp = realloc(driverTracker, driverSize * sizeof(*driverTracker)); - if (NULL == driverTracker) + + if (NULL == tmp) { + free(driverTracker); Log1(PCSC_LOG_CRITICAL, "Not enough memory"); driverSize = -1; (void)closedir(hpDir); return -1; } + driverTracker = tmp; /* clean the newly allocated entries */ for (i=driverSize-DRIVER_TRACKER_SIZE_STEP; i - * Copyright (C) 2002-2011 + * Copyright (C) 2002-2018 * Ludovic Rousseau * Redistribution and use in source and binary forms, with or without @@ -685,12 +685,13 @@ int main(int argc, char **argv) "writing " PCSCLITE_RUN_PID " failed: %s", strerror(errno)); } - (void)close(f); /* set mode so that the file is world readable even is umask is * restrictive * The file is used by libpcsclite */ - (void)chmod(PCSCLITE_RUN_PID, mode); + (void)fchmod(f, mode); + + (void)close(f); } else Log2(PCSC_LOG_CRITICAL, "cannot create " PCSCLITE_RUN_PID ": %s", @@ -835,7 +836,7 @@ static void print_version(void) { printf("%s version %s.\n", PACKAGE, VERSION); printf("Copyright (C) 1999-2002 by David Corcoran .\n"); - printf("Copyright (C) 2001-2015 by Ludovic Rousseau .\n"); + printf("Copyright (C) 2001-2018 by Ludovic Rousseau .\n"); printf("Copyright (C) 2003-2004 by Damien Sauveron .\n"); printf("Report bugs to .\n"); diff --git a/src/spy/pcsc-spy b/src/spy/pcsc-spy index cc246a3..85222c6 100755 --- a/src/spy/pcsc-spy +++ b/src/spy/pcsc-spy @@ -855,13 +855,16 @@ class PCSCdemultiplexer(object): start_time = int(sec) + int(usec) / 1000000. + lastest_result = "" while line != '': previous_thread = thread (thread, tail) = line.split('@') + if "<" in tail: + lastest_result = tail # in case the thread changes if previous_thread != thread: - # schedule the other thread so it has time to emtpy its + # schedule the other thread so it has time to empty its # queue time.sleep(.01) @@ -889,13 +892,9 @@ class PCSCdemultiplexer(object): for thread in threads: threads[thread].join() - try: - (code, rv, sec, usec) = _parse_rv(tail) - end_time = sec + usec / 1000000. - total_time = end_time - start_time - except ValueError: - # we have no return value of the latest PC/SC call - total_time = -1 + (code, rv, sec, usec) = _parse_rv(lastest_result) + end_time = sec + usec / 1000000. + total_time = end_time - start_time # compute some statistics thread_n = 1 diff --git a/src/winscard.c b/src/winscard.c index 577b40c..9f24cd7 100644 --- a/src/winscard.c +++ b/src/winscard.c @@ -583,9 +583,6 @@ LONG SCardReconnect(SCARDHANDLE hCard, DWORD dwShareMode, */ RFSetReaderEventState(rContext, SCARD_RESET); - /* - * Currently pcsc-lite keeps the card powered constantly - */ dwAtrLen = sizeof(rContext->readerState->cardAtr); if (SCARD_RESET_CARD == dwInitialization) rv = IFDPowerICC(rContext, IFD_RESET, @@ -1137,9 +1134,6 @@ LONG SCardEndTransaction(SCARDHANDLE hCard, DWORD dwDisposition) { DWORD dwAtrLen; - /* - * Currently pcsc-lite keeps the card always powered - */ dwAtrLen = sizeof(rContext->readerState->cardAtr); if (SCARD_RESET_CARD == dwDisposition) rv = IFDPowerICC(rContext, IFD_RESET, diff --git a/src/winscard_clnt.c b/src/winscard_clnt.c index 2b30854..7cd85ff 100644 --- a/src/winscard_clnt.c +++ b/src/winscard_clnt.c @@ -595,7 +595,7 @@ static LONG SCardEstablishContextTH(DWORD dwScope, rv = MessageSendWithHeader(CMD_VERSION, dwClientID, sizeof(veStr), &veStr); if (rv != SCARD_S_SUCCESS) - return rv; + goto cleanup; /* Read a message from the server */ rv = MessageReceive(&veStr, sizeof(veStr), dwClientID); @@ -603,14 +603,18 @@ static LONG SCardEstablishContextTH(DWORD dwScope, { Log1(PCSC_LOG_CRITICAL, "Your pcscd is too old and does not support CMD_VERSION"); - return SCARD_F_COMM_ERROR; + rv = SCARD_F_COMM_ERROR; + goto cleanup; } Log3(PCSC_LOG_INFO, "Server is protocol version %d:%d", veStr.major, veStr.minor); if (veStr.rv != SCARD_S_SUCCESS) - return veStr.rv; + { + rv = veStr.rv; + goto cleanup; + } } again: @@ -625,7 +629,7 @@ again: sizeof(scEstablishStruct), (void *) &scEstablishStruct); if (rv != SCARD_S_SUCCESS) - return rv; + goto cleanup; /* * Read the response from the server @@ -634,10 +638,13 @@ again: dwClientID); if (rv != SCARD_S_SUCCESS) - return rv; + goto cleanup; if (scEstablishStruct.rv != SCARD_S_SUCCESS) - return scEstablishStruct.rv; + { + rv = scEstablishStruct.rv; + goto cleanup; + } /* check we do not reuse an existing hContext */ if (NULL != SCardGetContextTH(scEstablishStruct.hContext)) @@ -652,6 +659,11 @@ again: */ rv = SCardAddContext(*phContext, dwClientID); + return rv; + +cleanup: + ClientCloseSession(dwClientID); + return rv; } diff --git a/src/winscard_svc.c b/src/winscard_svc.c index 871cef7..b845827 100644 --- a/src/winscard_svc.c +++ b/src/winscard_svc.c @@ -896,9 +896,7 @@ static LONG MSGRemoveContext(SCARDCONTEXT hContext, SCONTEXT * threadContext) { /* * if the card is locked by someone else we do not reset it - * and simulate a card removal */ - rv = SCARD_W_REMOVED_CARD; /* decrement card use */ (void)SCardDisconnect(hCard, SCARD_LEAVE_CARD);