Ticket #176: bug.0

File bug.0, 2.5 KB (added by ken, 8 months ago)

session demonstrating bug, and small patch to fix this specific error

Line 
1$ pkcs15-tool --reader 1 --read-public-key 46
2[pkcs15-tool] asn1.c:1369:asn1_encode_entry: encoding of ASN.1 object 'key' failed: Out of memory
3[pkcs15-tool] asn1.c:1369:asn1_encode_entry: encoding of ASN.1 object 'publicKey' failed: Out of memory
4Error encoding PEM key: Out of memory
5Segmentation fault
6
7$ pkcs15-tool --reader 1 --read-ssh-key 46
81024 3662527367 142858021714489371602557778084974718321558270719615204654695304286585745772263752008359944282410983963809820060393278708238714645121252120418019197870843366728417723268779359352672753204197897043291854989988568544846807956151638164995061959370136847974031703513264324049389621627216560769922000052065446266671
9ssh-rsa AAAAB3NzaC1yc2EAAAAFANpNu4cAAACBAMtvw22A3X0WUebKOytu0Brady/zn51irkwejonY0EcJSpuBuA4BGMcMSRSX8Gsr8BdEaODnSmVCGzASEKCejy3SFwOyVtDxxzbSMyHKfaoKJR3sbJVCprdKSnSIzE8PsfO8gBgnIDNaYLd77p7tqa5GQKaA6I7fQmK/CsW7Ngcv
10
11$ gcc -v
12Using built-in specs.
13Target: x86_64-pc-linux-gnu
14Configured with: /var/tmp/portage/sys-devel/gcc-4.1.2/work/gcc-4.1.2/configure --prefix=/usr --bindir=/usr/x86_64-pc-linux-gnu/gcc-bin/4.1.2 --includedir=/usr/lib/gcc/x86_64-pc-linux-gnu/4.1.2/include --datadir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.1.2 --mandir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.1.2/man --infodir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.1.2/info --with-gxx-include-dir=/usr/lib/gcc/x86_64-pc-linux-gnu/4.1.2/include/g++-v4 --host=x86_64-pc-linux-gnu --build=x86_64-pc-linux-gnu --disable-altivec --disable-nls --with-system-zlib --disable-checking --disable-werror --enable-secureplt --disable-libunwind-exceptions --enable-multilib --enable-libmudflap --disable-libssp --disable-libgcj --enable-languages=c,c++,treelang --enable-shared --enable-threads=posix --enable-__cxa_atexit --enable-clocale=gnu
15Thread model: posix
16gcc version 4.1.2 (Gentoo 4.1.2 p1.0.2)
17
18$ diff -u opensc-0.11.4-orig/src/tools/pkcs15-tool.c opensc-0.11.4/src/tools/pkcs15-tool.c
19--- opensc-0.11.4-orig/src/tools/pkcs15-tool.c  2007-06-30 01:55:58.000000000 -0700
20+++ opensc-0.11.4/src/tools/pkcs15-tool.c       2008-04-27 19:56:02.000000000 -0700
21@@ -1419,7 +1419,7 @@
22        struct sc_asn1_entry    asn1_pem_key[2],
23                                asn1_pem_key_items[3];
24        struct sc_algorithm_id algorithm;
25-       int key_len;
26+       size_t key_len;
27 
28        memset(&algorithm, 0, sizeof(algorithm));
29        algorithm.algorithm = alg_id;
30
31
32
33Bug #131 is related.  Generally there is a lot of use of "int" where
34"size_t" is more appropriate, and sometimes (especially in the passing
35of values via (void*) variables) this can bite hard when the assumption
36fails.