Diff

Differences From Artifact [36bd79ba26]:

To Artifact [e77001954d]:


   155    155   #define GSCIS_AID_CCC                 0xA0, 0x00, 0x00, 0x01, 0x16, 0xDB, 0x00
   156    156   
   157    157   #ifdef CACKEY_DEBUG
   158    158   #  ifdef HAVE_STDIO_H
   159    159   #    include <stdio.h>
   160    160   #  endif
   161    161   
   162         -#  define CACKEY_DEBUG_PRINTF(x...) { fprintf(stderr, "%s(): ", __func__); fprintf(stderr, x); fprintf(stderr, "\n"); }
   163         -#  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"); }
   164         -#  define CACKEY_DEBUG_PERROR(x) { fprintf(stderr, "%s(): ", __func__); perror(x); }
          162  +#  define CACKEY_DEBUG_PRINTF(x...) { fprintf(stderr, "%s():%i: ", __func__, __LINE__); fprintf(stderr, x); fprintf(stderr, "\n"); }
          163  +#  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"); }
          164  +#  define CACKEY_DEBUG_PERROR(x) { fprintf(stderr, "%s():%i: ", __func__, __LINE__); perror(x); }
   165    165   #  define free(x) { CACKEY_DEBUG_PRINTF("FREE(%p) (%s)", x, #x); free(x); }
   166    166   
   167         -static void *CACKEY_DEBUG_FUNC_MALLOC(size_t size, const char *func) {
          167  +static void *CACKEY_DEBUG_FUNC_MALLOC(size_t size, const char *func, int line) {
   168    168   	void *retval;
   169    169   
   170    170   	retval = malloc(size);
   171    171   
   172         -	fprintf(stderr, "%s(): ", func);
          172  +	fprintf(stderr, "%s():%i: ", func, line);
   173    173   	fprintf(stderr, "MALLOC() = %p", retval);
   174    174   	fprintf(stderr, "\n");
   175    175   
   176    176   	return(retval);
   177    177   }
   178    178   
   179         -static void *CACKEY_DEBUG_FUNC_REALLOC(void *ptr, size_t size, const char *func) {
          179  +static void *CACKEY_DEBUG_FUNC_REALLOC(void *ptr, size_t size, const char *func, int line) {
   180    180   	void *retval;
   181    181   
   182    182   	retval = realloc(ptr, size);
   183    183   
   184    184   	if (retval != ptr) {
   185         -		fprintf(stderr, "%s(): ", func);
          185  +		fprintf(stderr, "%s():%i: ", func, line);
   186    186   		fprintf(stderr, "REALLOC(%p) = %p", ptr, retval);
   187    187   		fprintf(stderr, "\n");
   188    188   	}
   189    189   
          190  +	return(retval);
          191  +}
          192  +
          193  +static char *CACKEY_DEBUG_FUNC_STRDUP(const char *ptr, const char *func, int line) {
          194  +	char *retval;
          195  +
          196  +	retval = strdup(ptr);
          197  +
          198  +	fprintf(stderr, "%s():%i: ", func, line);
          199  +	fprintf(stderr, "STRDUP_MALLOC() = %p", retval);
          200  +	fprintf(stderr, "\n");
          201  +
   190    202   	return(retval);
   191    203   }
   192    204   
   193    205   static const char *CACKEY_DEBUG_FUNC_TAG_TO_STR(unsigned char tag) {
   194    206   	switch (tag) {
   195    207   		case GSCIS_TAG_CARDID:
   196    208   			return("GSCIS_TAG_CARDID");
................................................................................
   422    434   		case 0x07:
   423    435   			return("CACKEY_TLV_APP_GENERIC | CACKEY_TLV_APP_SKI | CACKEY_TLV_APP_PKI");
   424    436   	}
   425    437   
   426    438   	return("INVALID");
   427    439   }
   428    440   
   429         -#  define malloc(x) CACKEY_DEBUG_FUNC_MALLOC(x, __func__)
   430         -#  define realloc(x, y) CACKEY_DEBUG_FUNC_REALLOC(x, y, __func__)
          441  +#  define malloc(x) CACKEY_DEBUG_FUNC_MALLOC(x, __func__, __LINE__)
          442  +#  define realloc(x, y) CACKEY_DEBUG_FUNC_REALLOC(x, y, __func__, __LINE__)
          443  +#  ifdef strdup
          444  +#    undef strdup
          445  +#  endif
          446  +#  define strdup(x) CACKEY_DEBUG_FUNC_STRDUP(x, __func__, __LINE__)
   431    447   #else
   432    448   #  define CACKEY_DEBUG_PRINTF(x...) /**/
   433    449   #  define CACKEY_DEBUG_PRINTBUF(f, x, y) /**/
   434    450   #  define CACKEY_DEBUG_PERROR(x) /**/
   435    451   #  define CACKEY_DEBUG_FUNC_TAG_TO_STR(x) "DEBUG_DISABLED"
   436    452   #  define CACKEY_DEBUG_FUNC_SCARDERR_TO_STR(x) "DEBUG_DISABLED"
   437    453   #  define CACKEY_DEBUG_FUNC_OBJID_TO_STR(x) "DEBUG_DISABLED"