Overview
Comment: | Added line numbers to debugging output
Added overloaded debugging strdup to check for leaks |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: | 709b50760d9414830471584ecbf79669521344b7 |
User & Date: | rkeene on 2010-05-15 00:34:57 |
Other Links: | manifest | tags |
Context
2010-05-15
| ||
00:39 | Updated to censor PIN in debugging output check-in: 0233c7b5fe user: rkeene tags: trunk | |
00:34 |
Added line numbers to debugging output
Added overloaded debugging strdup to check for leaks check-in: 709b50760d user: rkeene tags: trunk | |
00:25 |
Updated to select correct applet and file for given identity for sign/decrypt
Added more debugging for selecting a key for sign/decrypt check-in: 9fc3b9fa03 user: rkeene tags: trunk | |
Changes
Modified cackey.c from [36bd79ba26] to [e77001954d].
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
...
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
|
#define GSCIS_AID_CCC 0xA0, 0x00, 0x00, 0x01, 0x16, 0xDB, 0x00
#ifdef CACKEY_DEBUG
# ifdef HAVE_STDIO_H
# include <stdio.h>
# endif
# define CACKEY_DEBUG_PRINTF(x...) { fprintf(stderr, "%s(): ", __func__); fprintf(stderr, x); fprintf(stderr, "\n"); }
# define CACKEY_DEBUG_PRINTBUF(f, x, y) { unsigned char *TMPBUF; unsigned long idx; TMPBUF = (unsigned char *) (x); fprintf(stderr, "%s(): %s (%s/%lu = {%02x", __func__, f, #x, (unsigned long) (y), TMPBUF[0]); for (idx = 1; idx < (y); idx++) { fprintf(stderr, ", %02x", TMPBUF[idx]); }; fprintf(stderr, "})\n"); }
# define CACKEY_DEBUG_PERROR(x) { fprintf(stderr, "%s(): ", __func__); perror(x); }
# define free(x) { CACKEY_DEBUG_PRINTF("FREE(%p) (%s)", x, #x); free(x); }
static void *CACKEY_DEBUG_FUNC_MALLOC(size_t size, const char *func) {
void *retval;
retval = malloc(size);
fprintf(stderr, "%s(): ", func);
fprintf(stderr, "MALLOC() = %p", retval);
fprintf(stderr, "\n");
return(retval);
}
static void *CACKEY_DEBUG_FUNC_REALLOC(void *ptr, size_t size, const char *func) {
void *retval;
retval = realloc(ptr, size);
if (retval != ptr) {
fprintf(stderr, "%s(): ", func);
fprintf(stderr, "REALLOC(%p) = %p", ptr, retval);
fprintf(stderr, "\n");
}
return(retval);
}
static const char *CACKEY_DEBUG_FUNC_TAG_TO_STR(unsigned char tag) {
switch (tag) {
case GSCIS_TAG_CARDID:
return("GSCIS_TAG_CARDID");
................................................................................
case 0x07:
return("CACKEY_TLV_APP_GENERIC | CACKEY_TLV_APP_SKI | CACKEY_TLV_APP_PKI");
}
return("INVALID");
}
# define malloc(x) CACKEY_DEBUG_FUNC_MALLOC(x, __func__)
# define realloc(x, y) CACKEY_DEBUG_FUNC_REALLOC(x, y, __func__)
#else
# define CACKEY_DEBUG_PRINTF(x...) /**/
# define CACKEY_DEBUG_PRINTBUF(f, x, y) /**/
# define CACKEY_DEBUG_PERROR(x) /**/
# define CACKEY_DEBUG_FUNC_TAG_TO_STR(x) "DEBUG_DISABLED"
# define CACKEY_DEBUG_FUNC_SCARDERR_TO_STR(x) "DEBUG_DISABLED"
# define CACKEY_DEBUG_FUNC_OBJID_TO_STR(x) "DEBUG_DISABLED"
|
|
|
|
|
|
|
|
>
>
>
>
>
>
>
>
>
>
>
>
|
|
>
>
>
>
|
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
...
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
|
#define GSCIS_AID_CCC 0xA0, 0x00, 0x00, 0x01, 0x16, 0xDB, 0x00 #ifdef CACKEY_DEBUG # ifdef HAVE_STDIO_H # include <stdio.h> # endif # define CACKEY_DEBUG_PRINTF(x...) { fprintf(stderr, "%s():%i: ", __func__, __LINE__); fprintf(stderr, x); fprintf(stderr, "\n"); } # define CACKEY_DEBUG_PRINTBUF(f, x, y) { unsigned char *TMPBUF; unsigned long idx; TMPBUF = (unsigned char *) (x); fprintf(stderr, "%s():%i: %s (%s/%lu = {%02x", __func__, __LINE__, f, #x, (unsigned long) (y), TMPBUF[0]); for (idx = 1; idx < (y); idx++) { fprintf(stderr, ", %02x", TMPBUF[idx]); }; fprintf(stderr, "})\n"); } # define CACKEY_DEBUG_PERROR(x) { fprintf(stderr, "%s():%i: ", __func__, __LINE__); perror(x); } # define free(x) { CACKEY_DEBUG_PRINTF("FREE(%p) (%s)", x, #x); free(x); } static void *CACKEY_DEBUG_FUNC_MALLOC(size_t size, const char *func, int line) { void *retval; retval = malloc(size); fprintf(stderr, "%s():%i: ", func, line); fprintf(stderr, "MALLOC() = %p", retval); fprintf(stderr, "\n"); return(retval); } static void *CACKEY_DEBUG_FUNC_REALLOC(void *ptr, size_t size, const char *func, int line) { void *retval; retval = realloc(ptr, size); if (retval != ptr) { fprintf(stderr, "%s():%i: ", func, line); fprintf(stderr, "REALLOC(%p) = %p", ptr, retval); fprintf(stderr, "\n"); } return(retval); } static char *CACKEY_DEBUG_FUNC_STRDUP(const char *ptr, const char *func, int line) { char *retval; retval = strdup(ptr); fprintf(stderr, "%s():%i: ", func, line); fprintf(stderr, "STRDUP_MALLOC() = %p", retval); fprintf(stderr, "\n"); return(retval); } static const char *CACKEY_DEBUG_FUNC_TAG_TO_STR(unsigned char tag) { switch (tag) { case GSCIS_TAG_CARDID: return("GSCIS_TAG_CARDID"); ................................................................................ case 0x07: return("CACKEY_TLV_APP_GENERIC | CACKEY_TLV_APP_SKI | CACKEY_TLV_APP_PKI"); } return("INVALID"); } # define malloc(x) CACKEY_DEBUG_FUNC_MALLOC(x, __func__, __LINE__) # define realloc(x, y) CACKEY_DEBUG_FUNC_REALLOC(x, y, __func__, __LINE__) # ifdef strdup # undef strdup # endif # define strdup(x) CACKEY_DEBUG_FUNC_STRDUP(x, __func__, __LINE__) #else # define CACKEY_DEBUG_PRINTF(x...) /**/ # define CACKEY_DEBUG_PRINTBUF(f, x, y) /**/ # define CACKEY_DEBUG_PERROR(x) /**/ # define CACKEY_DEBUG_FUNC_TAG_TO_STR(x) "DEBUG_DISABLED" # define CACKEY_DEBUG_FUNC_SCARDERR_TO_STR(x) "DEBUG_DISABLED" # define CACKEY_DEBUG_FUNC_OBJID_TO_STR(x) "DEBUG_DISABLED" |
Added leakcheck/check-malloc-free.sh version [ebd6df1f69].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
#! /bin/bash TMPFILE="${TMPDIR:-/tmp}/malloc-free-check-$$${RANDOM}${RANDOM}${RANDOM}.tmp" egrep '(MALLOC|FREE|REALLOC)' "$@" | sed 's@^.*FREE(\(0x[0-9a-f]*\)).*$@free \1@;s@^.*MALLOC() = @malloc @;s@^.*REALLOC(\(0x[0-9a-f]*\)) = @realloc \1 @' > "${TMPFILE}" cat "${TMPFILE}" | while read op addr newaddr; do case "${op}" in malloc) if [ -z "${alloclist}" ]; then alloclist="${addr}" else alloclist="${alloclist} ${addr}" fi ;; free) if ! echo " ${alloclist} " | grep " ${addr} " >/dev/null; then if [ -z "${alloclist}" ]; then alloclist="!${addr}" else alloclist="${alloclist} !${addr}" fi continue fi alloclist="$(echo " ${alloclist} " | sed "s@ ${addr} @ @;s@^ *@@;s@ *\$@@")" ;; realloc) alloclist="$(echo " ${alloclist} " | sed "s@ ${addr} @ ${newaddr} @;s@^ *@@;s@ *\$@@")" ;; esac echo "${alloclist}" done | tail -1 | while read leftovers; do for leftover in ${leftovers}; do case "${leftover}" in !*) leftover="$(echo "${leftover}" | cut -c 2-)" echo "Double freed or never allocated ${leftover}:" grep "${leftover}" "$@" | sed 's@^@ @' echo '' ;; *) echo "Unfreed memory ${leftover}:" grep "${leftover}" "$@" | sed 's@^@ @' echo '' ;; esac done done rm -f "${TMPFILE}" |