scd: Replace all assert macros by the log_assert macro.

Signed-off-by: Werner Koch <wk@gnupg.org>
This commit is contained in:
Werner Koch 2021-03-31 19:16:05 +02:00
parent 6ca5407151
commit 1c16878efd
No known key found for this signature in database
GPG Key ID: E3FDFF218E45B72B
9 changed files with 35 additions and 44 deletions

View File

@ -27,7 +27,6 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <assert.h>
#include <signal.h> #include <signal.h>
#ifdef USE_NPTH #ifdef USE_NPTH
# include <unistd.h> # include <unistd.h>
@ -849,7 +848,7 @@ connect_pcsc_card (int slot)
{ {
long err; long err;
assert (slot >= 0 && slot < MAX_READER); log_assert (slot >= 0 && slot < MAX_READER);
if (reader_table[slot].pcsc.card) if (reader_table[slot].pcsc.card)
return SW_HOST_ALREADY_CONNECTED; return SW_HOST_ALREADY_CONNECTED;
@ -906,7 +905,7 @@ disconnect_pcsc_card (int slot)
{ {
long err; long err;
assert (slot >= 0 && slot < MAX_READER); log_assert (slot >= 0 && slot < MAX_READER);
if (!reader_table[slot].pcsc.card) if (!reader_table[slot].pcsc.card)
return 0; return 0;
@ -1478,7 +1477,7 @@ reset_ccid_reader (int slot)
if (err) if (err)
return err; return err;
/* If the reset was successful, update the ATR. */ /* If the reset was successful, update the ATR. */
assert (sizeof slotp->atr >= sizeof atr); log_assert (sizeof slotp->atr >= sizeof atr);
slotp->atrlen = atrlen; slotp->atrlen = atrlen;
memcpy (slotp->atr, atr, atrlen); memcpy (slotp->atr, atr, atrlen);
dump_reader_status (slot); dump_reader_status (slot);
@ -2918,7 +2917,7 @@ send_le (int slot, int class, int ins, int p0, int p1,
if (use_chaining && lc > 255) if (use_chaining && lc > 255)
{ {
apdu[apdulen] |= 0x10; apdu[apdulen] |= 0x10;
assert (use_chaining < 256); log_assert (use_chaining < 256);
lc_chunk = use_chaining; lc_chunk = use_chaining;
lc -= use_chaining; lc -= use_chaining;
} }
@ -2948,7 +2947,7 @@ send_le (int slot, int class, int ins, int p0, int p1,
exact_length_hack: exact_length_hack:
/* As a safeguard don't pass any garbage to the driver. */ /* As a safeguard don't pass any garbage to the driver. */
assert (apdulen <= apdu_buffer_size); log_assert (apdulen <= apdu_buffer_size);
memset (apdu+apdulen, 0, apdu_buffer_size - apdulen); memset (apdu+apdulen, 0, apdu_buffer_size - apdulen);
resultlen = result_buffer_size; resultlen = result_buffer_size;
rc = send_apdu (slot, apdu, apdulen, result, &resultlen, pininfo); rc = send_apdu (slot, apdu, apdulen, result, &resultlen, pininfo);
@ -3024,7 +3023,7 @@ send_le (int slot, int class, int ins, int p0, int p1,
xfree (result_buffer); xfree (result_buffer);
return SW_HOST_OUT_OF_CORE; return SW_HOST_OUT_OF_CORE;
} }
assert (resultlen < bufsize); log_assert (resultlen < bufsize);
memcpy (p, result, resultlen); memcpy (p, result, resultlen);
p += resultlen; p += resultlen;
} }
@ -3044,7 +3043,7 @@ send_le (int slot, int class, int ins, int p0, int p1,
apdu[apdulen++] = 0; apdu[apdulen++] = 0;
apdu[apdulen++] = 0; apdu[apdulen++] = 0;
apdu[apdulen++] = len; apdu[apdulen++] = len;
assert (apdulen <= apdu_buffer_size); log_assert (apdulen <= apdu_buffer_size);
memset (apdu+apdulen, 0, apdu_buffer_size - apdulen); memset (apdu+apdulen, 0, apdu_buffer_size - apdulen);
resultlen = result_buffer_size; resultlen = result_buffer_size;
rc = send_apdu (slot, apdu, apdulen, result, &resultlen, NULL); rc = send_apdu (slot, apdu, apdulen, result, &resultlen, NULL);
@ -3304,7 +3303,7 @@ apdu_send_direct (int slot, size_t extended_length,
xfree (result_buffer); xfree (result_buffer);
return SW_HOST_OUT_OF_CORE; return SW_HOST_OUT_OF_CORE;
} }
assert (resultlen < bufsize); log_assert (resultlen < bufsize);
memcpy (p, result, resultlen); memcpy (p, result, resultlen);
p += resultlen; p += resultlen;
} }

View File

@ -74,7 +74,6 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <assert.h>
#include <time.h> #include <time.h>
#include "scdaemon.h" #include "scdaemon.h"
@ -229,7 +228,7 @@ do_readcert (app_t app, const char *certid,
else else
return gpg_error (GPG_ERR_INV_OBJ); return gpg_error (GPG_ERR_INV_OBJ);
totobjlen = objlen + hdrlen; totobjlen = objlen + hdrlen;
assert (totobjlen <= buflen); log_assert (totobjlen <= buflen);
err = parse_ber_header (&p, &n, &class, &tag, &constructed, err = parse_ber_header (&p, &n, &class, &tag, &constructed,
&ndef, &objlen, &hdrlen); &ndef, &objlen, &hdrlen);
@ -260,7 +259,7 @@ do_readcert (app_t app, const char *certid,
if ( !(class == CLASS_UNIVERSAL && tag == TAG_SEQUENCE && constructed) ) if ( !(class == CLASS_UNIVERSAL && tag == TAG_SEQUENCE && constructed) )
return gpg_error (GPG_ERR_INV_OBJ); return gpg_error (GPG_ERR_INV_OBJ);
totobjlen = objlen + hdrlen; totobjlen = objlen + hdrlen;
assert (save_p + totobjlen <= buffer + buflen); log_assert (save_p + totobjlen <= buffer + buflen);
memmove (buffer, save_p, totobjlen); memmove (buffer, save_p, totobjlen);
} }

View File

@ -31,7 +31,6 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <assert.h>
#include <time.h> #include <time.h>
#include <ctype.h> #include <ctype.h>

View File

@ -48,7 +48,6 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdarg.h> #include <stdarg.h>
#include <string.h> #include <string.h>
#include <assert.h>
#include <time.h> #include <time.h>
#include "scdaemon.h" #include "scdaemon.h"
@ -466,7 +465,7 @@ get_cached_data (app_t app, int tag,
/* Okay, cache it. */ /* Okay, cache it. */
for (c=app->app_local->cache; c; c = c->next) for (c=app->app_local->cache; c; c = c->next)
assert (c->tag != tag); log_assert (c->tag != tag);
c = xtrymalloc (sizeof *c + len); c = xtrymalloc (sizeof *c + len);
if (c) if (c)
@ -505,7 +504,7 @@ flush_cache_item (app_t app, int tag)
for (c=app->app_local->cache; c ; c = c->next) for (c=app->app_local->cache; c ; c = c->next)
{ {
assert (c->tag != tag); /* Oops: duplicated entry. */ log_assert (c->tag != tag); /* Oops: duplicated entry. */
} }
return; return;
} }
@ -1447,7 +1446,7 @@ retrieve_fpr_from_card (app_t app, int keyno, char *fpr)
unsigned char *value; unsigned char *value;
size_t valuelen; size_t valuelen;
assert (keyno >=0 && keyno <= 2); log_assert (keyno >=0 && keyno <= 2);
relptr = get_one_do (app, 0x00C5, &value, &valuelen, NULL); relptr = get_one_do (app, 0x00C5, &value, &valuelen, NULL);
if (relptr && valuelen >= 60) if (relptr && valuelen >= 60)
@ -2056,7 +2055,7 @@ send_keypair_info (app_t app, ctrl_t ctrl, int key)
if (err) if (err)
goto leave; goto leave;
assert (keyno >= 0 && keyno <= 2); log_assert (keyno >= 0 && keyno <= 2);
if (!app->app_local->pk[keyno].key) if (!app->app_local->pk[keyno].key)
goto leave; /* No such key - ignore. */ goto leave; /* No such key - ignore. */
@ -3533,7 +3532,7 @@ do_change_pin (app_t app, ctrl_t ctrl, const char *chvnostr,
else else
{ {
/* Version 2 cards. */ /* Version 2 cards. */
assert (chvno == 1 || chvno == 3); log_assert (chvno == 1 || chvno == 3);
if (use_pinpad) if (use_pinpad)
{ {
@ -3594,7 +3593,7 @@ does_key_exist (app_t app, int keyidx, int generating, int force)
size_t buflen, n; size_t buflen, n;
int i; int i;
assert (keyidx >=0 && keyidx <= 2); log_assert (keyidx >=0 && keyidx <= 2);
if (iso7816_get_data (app_get_slot (app), 0, 0x006E, &buffer, &buflen)) if (iso7816_get_data (app_get_slot (app), 0, 0x006E, &buffer, &buflen))
{ {
@ -3634,7 +3633,7 @@ add_tlv (unsigned char *buffer, unsigned int tag, size_t length)
{ {
unsigned char *p = buffer; unsigned char *p = buffer;
assert (tag <= 0xffff); log_assert (tag <= 0xffff);
if ( tag > 0xff ) if ( tag > 0xff )
*p++ = tag >> 8; *p++ = tag >> 8;
*p++ = tag; *p++ = tag;
@ -3698,7 +3697,7 @@ build_privkey_template (app_t app, int keyno,
/* Get the required length for E. Rounded up to the nearest byte */ /* Get the required length for E. Rounded up to the nearest byte */
rsa_e_reqlen = (app->app_local->keyattr[keyno].rsa.e_bits + 7) / 8; rsa_e_reqlen = (app->app_local->keyattr[keyno].rsa.e_bits + 7) / 8;
assert (rsa_e_len <= rsa_e_reqlen); log_assert (rsa_e_len <= rsa_e_reqlen);
/* Build the 7f48 cardholder private key template. */ /* Build the 7f48 cardholder private key template. */
datalen = 0; datalen = 0;
@ -3797,7 +3796,7 @@ build_privkey_template (app_t app, int keyno,
/* Sanity check. We don't know the exact length because we /* Sanity check. We don't know the exact length because we
allocated 3 bytes for the first length header. */ allocated 3 bytes for the first length header. */
assert (tp - template <= template_size); log_assert (tp - template <= template_size);
*result = template; *result = template;
*resultlen = tp - template; *resultlen = tp - template;
@ -3904,7 +3903,7 @@ build_ecc_privkey_template (app_t app, int keyno,
tp += ecc_q_len; tp += ecc_q_len;
} }
assert (tp - template == template_size); log_assert (tp - template == template_size);
*result = template; *result = template;
*resultlen = tp - template; *resultlen = tp - template;
@ -3922,7 +3921,7 @@ change_keyattr (app_t app, ctrl_t ctrl,
{ {
gpg_error_t err; gpg_error_t err;
assert (keyno >=0 && keyno <= 2); log_assert (keyno >=0 && keyno <= 2);
/* Prepare for storing the key. */ /* Prepare for storing the key. */
err = verify_chv3 (app, ctrl, pincb, pincb_arg); err = verify_chv3 (app, ctrl, pincb, pincb_arg);
@ -4437,7 +4436,7 @@ rsa_writekey (app_t app, ctrl_t ctrl,
0xC1 <length> prime p 0xC1 <length> prime p
0xC2 <length> prime q 0xC2 <length> prime q
*/ */
assert (rsa_e_len <= 4); log_assert (rsa_e_len <= 4);
template_len = (1 + 1 + 4 template_len = (1 + 1 + 4
+ 1 + 1 + rsa_p_len + 1 + 1 + rsa_p_len
+ 1 + 1 + rsa_q_len); + 1 + 1 + rsa_q_len);
@ -4468,7 +4467,7 @@ rsa_writekey (app_t app, ctrl_t ctrl,
memcpy (tp, rsa_q, rsa_q_len); memcpy (tp, rsa_q, rsa_q_len);
tp += rsa_q_len; tp += rsa_q_len;
assert (tp - template == template_len); log_assert (tp - template == template_len);
/* Prepare for storing the key. */ /* Prepare for storing the key. */
err = verify_chv3 (app, ctrl, pincb, pincb_arg); err = verify_chv3 (app, ctrl, pincb, pincb_arg);
@ -5019,7 +5018,7 @@ compare_fingerprint (app_t app, int keyno, unsigned char *sha1fpr)
size_t buflen, n; size_t buflen, n;
int rc, i; int rc, i;
assert (keyno >= 0 && keyno <= 2); log_assert (keyno >= 0 && keyno <= 2);
rc = get_cached_data (app, 0x006E, &buffer, &buflen, 0, 0); rc = get_cached_data (app, 0x006E, &buffer, &buflen, 0, 0);
if (rc) if (rc)
@ -5262,7 +5261,7 @@ do_sign (app_t app, ctrl_t ctrl, const char *keyidstr, int hashalgo,
if (hashalgo == GCRY_MD_ ## a && (d) ) \ if (hashalgo == GCRY_MD_ ## a && (d) ) \
{ \ { \
datalen = sizeof b ## _prefix + indatalen; \ datalen = sizeof b ## _prefix + indatalen; \
assert (datalen <= sizeof data); \ log_assert (datalen <= sizeof data); \
memcpy (data, b ## _prefix, sizeof b ## _prefix); \ memcpy (data, b ## _prefix, sizeof b ## _prefix); \
memcpy (data + sizeof b ## _prefix, indata, indatalen); \ memcpy (data + sizeof b ## _prefix, indata, indatalen); \
} }

View File

@ -34,7 +34,6 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <assert.h>
#include <time.h> #include <time.h>
#include "scdaemon.h" #include "scdaemon.h"
@ -3426,9 +3425,9 @@ read_p15_info (app_t app)
return err; return err;
/* Read certificate information. */ /* Read certificate information. */
assert (!app->app_local->certificate_info); log_assert (!app->app_local->certificate_info);
assert (!app->app_local->trusted_certificate_info); log_assert (!app->app_local->trusted_certificate_info);
assert (!app->app_local->useful_certificate_info); log_assert (!app->app_local->useful_certificate_info);
err = read_ef_cdf (app, app->app_local->odf.certificates, 'c', err = read_ef_cdf (app, app->app_local->odf.certificates, 'c',
&app->app_local->certificate_info); &app->app_local->certificate_info);
if (!err || gpg_err_code (err) == GPG_ERR_NO_DATA) if (!err || gpg_err_code (err) == GPG_ERR_NO_DATA)
@ -3443,7 +3442,7 @@ read_p15_info (app_t app)
return err; return err;
/* Read information about public keys. */ /* Read information about public keys. */
assert (!app->app_local->public_key_info); log_assert (!app->app_local->public_key_info);
err = read_ef_pukdf (app, app->app_local->odf.public_keys, err = read_ef_pukdf (app, app->app_local->odf.public_keys,
&app->app_local->public_key_info); &app->app_local->public_key_info);
if (!err || gpg_err_code (err) == GPG_ERR_NO_DATA) if (!err || gpg_err_code (err) == GPG_ERR_NO_DATA)
@ -3455,7 +3454,7 @@ read_p15_info (app_t app)
return err; return err;
/* Read information about private keys. */ /* Read information about private keys. */
assert (!app->app_local->private_key_info); log_assert (!app->app_local->private_key_info);
err = read_ef_prkdf (app, app->app_local->odf.private_keys, err = read_ef_prkdf (app, app->app_local->odf.private_keys,
&app->app_local->private_key_info); &app->app_local->private_key_info);
if (gpg_err_code (err) == GPG_ERR_NO_DATA) if (gpg_err_code (err) == GPG_ERR_NO_DATA)
@ -3464,7 +3463,7 @@ read_p15_info (app_t app)
return err; return err;
/* Read information about authentication objects. */ /* Read information about authentication objects. */
assert (!app->app_local->auth_object_info); log_assert (!app->app_local->auth_object_info);
err = read_ef_aodf (app, app->app_local->odf.auth_objects, err = read_ef_aodf (app, app->app_local->odf.auth_objects,
&app->app_local->auth_object_info); &app->app_local->auth_object_info);
if (gpg_err_code (err) == GPG_ERR_NO_DATA) if (gpg_err_code (err) == GPG_ERR_NO_DATA)

View File

@ -27,7 +27,6 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <assert.h>
#include <time.h> #include <time.h>
#include "scdaemon.h" #include "scdaemon.h"
@ -1388,7 +1387,7 @@ send_keypairinfo (app_t app, ctrl_t ctrl, prkdf_object_t keyinfo)
} }
else else
{ {
assert (strlen (gripstr) == 40); log_assert (strlen (gripstr) == 40);
send_status_info (ctrl, "KEYPAIRINFO", send_status_info (ctrl, "KEYPAIRINFO",
gripstr, 40, gripstr, 40,
buf, strlen (buf), buf, strlen (buf),
@ -1484,7 +1483,7 @@ readcert_by_cdf (app_t app, cdf_object_t cdf,
goto leave; goto leave;
} }
totobjlen = objlen + hdrlen; totobjlen = objlen + hdrlen;
assert (totobjlen <= buflen); log_assert (totobjlen <= buflen);
err = parse_ber_header (&p, &n, &class, &tag, &constructed, err = parse_ber_header (&p, &n, &class, &tag, &constructed,
&ndef, &objlen, &hdrlen); &ndef, &objlen, &hdrlen);
@ -1515,7 +1514,7 @@ readcert_by_cdf (app_t app, cdf_object_t cdf,
goto leave; goto leave;
} }
totobjlen = objlen + hdrlen; totobjlen = objlen + hdrlen;
assert (save_p + totobjlen <= buffer + buflen); log_assert (save_p + totobjlen <= buffer + buflen);
memmove (buffer, save_p, totobjlen); memmove (buffer, save_p, totobjlen);
} }

View File

@ -22,7 +22,6 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <assert.h>
#include <gpg-error.h> #include <gpg-error.h>
#include "../common/logging.h" #include "../common/logging.h"

View File

@ -78,7 +78,6 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <assert.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <fcntl.h> #include <fcntl.h>
@ -3189,7 +3188,7 @@ ccid_transceive (ccid_driver_t handle,
apdu = apdu_buf; apdu = apdu_buf;
apdulen = apdu_buflen; apdulen = apdu_buflen;
assert (apdulen); log_assert (apdulen);
/* Construct an I-Block. */ /* Construct an I-Block. */
tpdu = msg + hdrlen; tpdu = msg + hdrlen;

View File

@ -28,7 +28,6 @@
#include <stdarg.h> #include <stdarg.h>
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
#include <assert.h>
#include <time.h> #include <time.h>
#include <fcntl.h> #include <fcntl.h>
#ifndef HAVE_W32_SYSTEM #ifndef HAVE_W32_SYSTEM