test failures because of a global-buffer-overflow
Our Gentoo Tinderbox reported a test failure at bug 914042 (see attached build.log and test-suite.log) because of a global-buffer-overflow:
# libcacard-DEBUG: vreader_xfr_bytes: CLS=0x80,INS=0x4c,P1=0x12,P2=0x0,Lc=2,Le=256 get acr
==223==ERROR: AddressSanitizer: global-buffer-overflow on address 0x7f72649214bc at pc 0x7f7264906fc8 bp 0x7ffe24ba0aa0 sp 0x7ffe24ba0a90
READ of size 4 at 0x7f72649214bc thread T0
#0 0x7f7264906fc7 in cac_aca_get_applet_acr_coid src/cac-aca.c:814
#1 0x7f7264906fc7 in cac_aca_get_applet_acr_response_simpletlv src/cac-aca.c:1170
#2 0x7f7264906fc7 in cac_aca_get_applet_acr_response src/cac-aca.c:1308
#3 0x7f7264900a29 in cac_applet_aca_process_apdu src/cac.c:657
#4 0x7f72649097c5 in vcard_process_apdu src/card_7816.c:787
#5 0x7f7264911e79 in vreader_xfr_bytes src/vreader.c:273
#6 0x555c67185d0c in get_acr tests/libcacard.c:354
#7 0x555c671883a4 in test_cac_aca tests/libcacard.c:516
#8 0x7f72648338ad (/usr/lib64/libglib-2.0.so.0+0x838ad)
#9 0x7f72648336a2 (/usr/lib64/libglib-2.0.so.0+0x836a2)
#10 0x7f7264833dc1 in g_test_run_suite (/usr/lib64/libglib-2.0.so.0+0x83dc1)
#11 0x7f7264833e47 in g_test_run (/usr/lib64/libglib-2.0.so.0+0x83e47)
#12 0x555c6706b951 in main tests/libcacard.c:1117
#13 0x7f7264423c89 (/lib64/libc.so.6+0x23c89)
#14 0x7f7264423d44 in __libc_start_main (/lib64/libc.so.6+0x23d44)
#15 0x555c6706bb20 in _start (/var/tmp/portage/app-emulation/libcacard-2.6.0/work/libcacard-2.6.0/tests/.libs/libcacard+0xeb20)
0x7f72649214bc is located 36 bytes before global variable 'service_table' defined in 'src/cac-aca.c:290:29' (0x7f72649214e0) of size 360
0x7f72649214bc is located 4 bytes after global variable 'applets_table' defined in 'src/cac-aca.c:447:20' (0x7f7264920200) of size 4792
SUMMARY: AddressSanitizer: global-buffer-overflow src/cac-aca.c:814 in cac_aca_get_applet_acr_coid
Shadow bytes around the buggy address:
0x7f7264921200: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x7f7264921280: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x7f7264921300: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x7f7264921380: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x7f7264921400: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x7f7264921480: 00 00 00 00 00 00 00[f9]f9 f9 f9 f9 00 00 00 00
0x7f7264921500: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x7f7264921580: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x7f7264921600: 00 00 00 00 00 00 00 00 00 f9 f9 f9 f9 f9 f9 f9
0x7f7264921680: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x7f7264921700: 00 f9 f9 f9 f9 f9 f9 f9 00 00 00 00 00 00 00 00
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
Heap left redzone: fa
Freed heap region: fd
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack after return: f5
Stack use after scope: f8
Global redzone: f9
Global init order: f6
Poisoned by user: f7
Container overflow: fc
Array cookie: ac
Intra object redzone: bb
ASan internal: fe
Left alloca redzone: ca
Right alloca redzone: cb
==223==ABORTING
I didn't look deeply into the issue and I don't know if the bug is in the unittest itself or it is in the library involved in the test (and then possible security implications) If I can help further, please let me know.