Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix data race issue accessing a logging variable
The struct timeval used in log_line() can't be accessed in a atomic way so we should protect it using a mutex. ================== WARNING: ThreadSanitizer: data race (pid=5391) Read of size 8 at 0x55b3bba7b950 by thread T3 (mutexes: write M17): #0 log_line /PCSC-debug/src/debuglog.c:217 (pcscd+0x9d7e) #1 log_msg /PCSC-debug/src/debuglog.c:148 (pcscd+0x9a85) #2 IFDHPowerICC <null> (libccid.so+0x8a54) #3 EHStatusHandlerThread /PCSC-debug/src/eventhandler.c:395 (pcscd+0xbafe) Previous write of size 8 at 0x55b3bba7b950 by main thread: #0 log_line /PCSC-debug/src/debuglog.c:232 (pcscd+0x9e77) #1 log_msg /PCSC-debug/src/debuglog.c:148 (pcscd+0x9a85) #2 get_driver /PCSC-debug/src/hotplug_libudev.c:298 (pcscd+0x1f75d) #3 HPAddDevice /PCSC-debug/src/hotplug_libudev.c:394 (pcscd+0x1ff32) #4 HPScanUSB /PCSC-debug/src/hotplug_libudev.c:579 (pcscd+0x209db) #5 HPRegisterForHotplugEvents /PCSC-debug/src/hotplug_libudev.c:761 (pcscd+0x21255) #6 main /PCSC-debug/src/pcscdaemon.c:766 (pcscd+0xe6fa) Location is global 'last_time.3' of size 16 at 0x55b3bba7b950 (pcscd+0x35950) Mutex M17 (0x7b0c000014d0) created at: #0 pthread_mutex_init ../../../../src/libsanitizer/tsan/ tsan_interceptors_posix.cpp:1295 (libtsan.so.2+0x50468) #1 RFAddReader /PCSC-debug/src/readerfactory.c:355 (pcscd+0x10b8c) #2 HPAddDevice /PCSC-debug/src/hotplug_libudev.c:512 (pcscd+0x205b0) #3 HPScanUSB /PCSC-debug/src/hotplug_libudev.c:579 (pcscd+0x209db) #4 HPRegisterForHotplugEvents /PCSC-debug/src/hotplug_libudev.c:761 (pcscd+0x21255) #5 main /PCSC-debug/src/pcscdaemon.c:766 (pcscd+0xe6fa) Thread T3 (tid=5395, running) created by main thread at: #0 pthread_create ../../../../src/libsanitizer/tsan/ tsan_interceptors_posix.cpp:1001 (libtsan.so.2+0x5e686) #1 ThreadCreate /PCSC-debug/src/utils.c:184 (pcscd+0x21755) #2 EHSpawnEventHandler /PCSC-debug/src/eventhandler.c:233 (pcscd+0xb2d9) #3 RFAddReader /PCSC-debug/src/readerfactory.c:397 (pcscd+0x10f1a) #4 HPAddDevice /PCSC-debug/src/hotplug_libudev.c:512 (pcscd+0x205b0) #5 HPScanUSB /PCSC-debug/src/hotplug_libudev.c:579 (pcscd+0x209db) #6 HPRegisterForHotplugEvents /PCSC-debug/src/hotplug_libudev.c:761 (pcscd+0x21255) #7 main /PCSC-debug/src/pcscdaemon.c:766 (pcscd+0xe6fa) SUMMARY: ThreadSanitizer: data race /PCSC-debug/src/debuglog.c:217 in log_line ================== Thanks to Stefan Ehmann for the bug report and patch.
- Loading branch information