gpgsm: Replace all assert calls by log_assert.

--

Signed-off-by: Werner Koch <wk@gnupg.org>
This commit is contained in:
Werner Koch 2020-07-08 14:40:34 +02:00
parent a6a4bbf6de
commit 9ee975d588
No known key found for this signature in database
GPG Key ID: E3FDFF218E45B72B
19 changed files with 29 additions and 44 deletions

View File

@ -25,7 +25,6 @@
#include <errno.h> #include <errno.h>
#include <unistd.h> #include <unistd.h>
#include <time.h> #include <time.h>
#include <assert.h>
#ifdef HAVE_LOCALE_H #ifdef HAVE_LOCALE_H
#include <locale.h> #include <locale.h>
#endif #endif
@ -480,7 +479,7 @@ gpgsm_scd_pksign (ctrl_t ctrl, const char *keyid, const char *desc,
if (rc) if (rc)
return rc; return rc;
assert (gcry_sexp_canon_len (*r_buf, *r_buflen, NULL, NULL)); log_assert (gcry_sexp_canon_len (*r_buf, *r_buflen, NULL, NULL));
return 0; return 0;
} }
@ -542,7 +541,7 @@ gpgsm_agent_pkdecrypt (ctrl_t ctrl, const char *keygrip, const char *desc,
if (rc) if (rc)
return rc; return rc;
assert ( DIM(line) >= 50 ); log_assert ( DIM(line) >= 50 );
snprintf (line, DIM(line), "SETKEY %s", keygrip); snprintf (line, DIM(line), "SETKEY %s", keygrip);
rc = assuan_transact (agent_ctx, line, NULL, NULL, NULL, NULL, NULL, NULL); rc = assuan_transact (agent_ctx, line, NULL, NULL, NULL, NULL, NULL, NULL);
if (rc) if (rc)

View File

@ -25,7 +25,6 @@
#include <errno.h> #include <errno.h>
#include <unistd.h> #include <unistd.h>
#include <time.h> #include <time.h>
#include <assert.h>
#include <ctype.h> #include <ctype.h>
#include "gpgsm.h" #include "gpgsm.h"
@ -283,7 +282,7 @@ start_dirmngr (ctrl_t ctrl)
{ {
gpg_error_t err; gpg_error_t err;
assert (! dirmngr_ctx_locked); log_assert (! dirmngr_ctx_locked);
dirmngr_ctx_locked = 1; dirmngr_ctx_locked = 1;
err = start_dirmngr_ext (ctrl, &dirmngr_ctx); err = start_dirmngr_ext (ctrl, &dirmngr_ctx);
@ -313,7 +312,7 @@ start_dirmngr2 (ctrl_t ctrl)
{ {
gpg_error_t err; gpg_error_t err;
assert (! dirmngr2_ctx_locked); log_assert (! dirmngr2_ctx_locked);
dirmngr2_ctx_locked = 1; dirmngr2_ctx_locked = 1;
err = start_dirmngr_ext (ctrl, &dirmngr2_ctx); err = start_dirmngr_ext (ctrl, &dirmngr2_ctx);

View File

@ -26,7 +26,6 @@
#include <unistd.h> #include <unistd.h>
#include <time.h> #include <time.h>
#include <stdarg.h> #include <stdarg.h>
#include <assert.h>
#include "gpgsm.h" #include "gpgsm.h"
#include <gcrypt.h> #include <gcrypt.h>

View File

@ -27,7 +27,6 @@
#include <errno.h> #include <errno.h>
#include <unistd.h> #include <unistd.h>
#include <time.h> #include <time.h>
#include <assert.h>
#include "gpgsm.h" #include "gpgsm.h"
#include <gcrypt.h> #include <gcrypt.h>
@ -169,12 +168,12 @@ do_encode_md (gcry_md_hd_t md, int algo, int pkalgo, unsigned int nbits,
frame[n++] = 0; frame[n++] = 0;
frame[n++] = 1; /* block type */ frame[n++] = 1; /* block type */
i = nframe - len - asnlen -3 ; i = nframe - len - asnlen -3 ;
assert ( i > 1 ); log_assert ( i > 1 );
memset ( frame+n, 0xff, i ); n += i; memset ( frame+n, 0xff, i ); n += i;
frame[n++] = 0; frame[n++] = 0;
memcpy ( frame+n, asn, asnlen ); n += asnlen; memcpy ( frame+n, asn, asnlen ); n += asnlen;
memcpy ( frame+n, gcry_md_read(md, algo), len ); n += len; memcpy ( frame+n, gcry_md_read(md, algo), len ); n += len;
assert ( n == nframe ); log_assert ( n == nframe );
} }
if (DBG_CRYPTO) if (DBG_CRYPTO)
{ {

View File

@ -24,7 +24,6 @@
#include <errno.h> #include <errno.h>
#include <unistd.h> #include <unistd.h>
#include <time.h> #include <time.h>
#include <assert.h>
#ifdef HAVE_LOCALE_H #ifdef HAVE_LOCALE_H
#include <locale.h> #include <locale.h>
#endif #endif
@ -654,7 +653,7 @@ pretty_es_print_sexp (estream_t fp, const unsigned char *buf, size_t buflen)
return; return;
} }
len = gcry_sexp_sprint (sexp, GCRYSEXP_FMT_ADVANCED, NULL, 0); len = gcry_sexp_sprint (sexp, GCRYSEXP_FMT_ADVANCED, NULL, 0);
assert (len); log_assert (len);
result = xtrymalloc (len); result = xtrymalloc (len);
if (!result) if (!result)
{ {
@ -663,7 +662,7 @@ pretty_es_print_sexp (estream_t fp, const unsigned char *buf, size_t buflen)
return; return;
} }
len = gcry_sexp_sprint (sexp, GCRYSEXP_FMT_ADVANCED, result, len); len = gcry_sexp_sprint (sexp, GCRYSEXP_FMT_ADVANCED, result, len);
assert (len); log_assert (len);
for (p = result; len; len--, p++) for (p = result; len; len--, p++)
{ {
if (*p == '\n') if (*p == '\n')

View File

@ -25,7 +25,6 @@
#include <errno.h> #include <errno.h>
#include <unistd.h> #include <unistd.h>
#include <time.h> #include <time.h>
#include <assert.h>
#include "gpgsm.h" #include "gpgsm.h"
#include <gcrypt.h> #include <gcrypt.h>

View File

@ -24,7 +24,6 @@
#include <errno.h> #include <errno.h>
#include <unistd.h> #include <unistd.h>
#include <time.h> #include <time.h>
#include <assert.h>
#include "gpgsm.h" #include "gpgsm.h"
#include <gcrypt.h> #include <gcrypt.h>

View File

@ -59,7 +59,6 @@
#include <errno.h> #include <errno.h>
#include <unistd.h> #include <unistd.h>
#include <time.h> #include <time.h>
#include <assert.h>
#include "gpgsm.h" #include "gpgsm.h"
#include <gcrypt.h> #include <gcrypt.h>
@ -448,7 +447,7 @@ proc_parameters (ctrl_t ctrl, struct para_data_s *para,
char *cardkeyid = NULL; char *cardkeyid = NULL;
/* Check that we have all required parameters; */ /* Check that we have all required parameters; */
assert (get_parameter (para, pKEYTYPE, 0)); log_assert (get_parameter (para, pKEYTYPE, 0));
/* There is a problem with pkcs-10 on how to use ElGamal because it /* There is a problem with pkcs-10 on how to use ElGamal because it
is expected that a PK algorithm can always be used for is expected that a PK algorithm can always be used for
@ -915,7 +914,7 @@ create_request (ctrl_t ctrl,
for (seq=0; (s = get_parameter_value (para, pNAMEDNS, seq)); seq++) for (seq=0; (s = get_parameter_value (para, pNAMEDNS, seq)); seq++)
{ {
len = strlen (s); len = strlen (s);
assert (len); log_assert (len);
snprintf (numbuf, DIM(numbuf), "%u:", (unsigned int)len); snprintf (numbuf, DIM(numbuf), "%u:", (unsigned int)len);
buf = p = xtrymalloc (11 + strlen (numbuf) + len + 3); buf = p = xtrymalloc (11 + strlen (numbuf) + len + 3);
if (!buf) if (!buf)
@ -942,7 +941,7 @@ create_request (ctrl_t ctrl,
for (seq=0; (s = get_parameter_value (para, pNAMEURI, seq)); seq++) for (seq=0; (s = get_parameter_value (para, pNAMEURI, seq)); seq++)
{ {
len = strlen (s); len = strlen (s);
assert (len); log_assert (len);
snprintf (numbuf, DIM(numbuf), "%u:", (unsigned int)len); snprintf (numbuf, DIM(numbuf), "%u:", (unsigned int)len);
buf = p = xtrymalloc (6 + strlen (numbuf) + len + 3); buf = p = xtrymalloc (6 + strlen (numbuf) + len + 3);
if (!buf) if (!buf)
@ -1322,6 +1321,10 @@ create_request (ctrl_t ctrl,
size_t qlen, derlen; size_t qlen, derlen;
unsigned char *der; unsigned char *der;
/* FIXME: This assumes that the to-be-certified key uses the
* same algorithm as the certification key - this is not
* always the case; in fact it is common that they
* differ. */
err = get_ecc_q_from_canon_sexp (sigkey, sigkeylen, &q, &qlen); err = get_ecc_q_from_canon_sexp (sigkey, sigkeylen, &q, &qlen);
if (err) if (err)
{ {

View File

@ -27,7 +27,6 @@
#include <errno.h> #include <errno.h>
#include <unistd.h> #include <unistd.h>
#include <time.h> #include <time.h>
#include <assert.h>
#include "gpgsm.h" #include "gpgsm.h"
#include <gcrypt.h> #include <gcrypt.h>
@ -594,7 +593,7 @@ decrypt_filter (void *arg,
*inused = inlen + parm->helpblocklen; *inused = inlen + parm->helpblocklen;
if (inlen) if (inlen)
{ {
assert (inlen >= blklen); log_assert (inlen >= blklen);
if (parm->any_data) if (parm->any_data)
{ {
gcry_cipher_decrypt (parm->hd, (char*)outbuf+blklen, inlen, gcry_cipher_decrypt (parm->hd, (char*)outbuf+blklen, inlen,

View File

@ -24,7 +24,6 @@
#include <errno.h> #include <errno.h>
#include <unistd.h> #include <unistd.h>
#include <time.h> #include <time.h>
#include <assert.h>
#include "gpgsm.h" #include "gpgsm.h"
#include <gcrypt.h> #include <gcrypt.h>

View File

@ -28,7 +28,6 @@
#include <errno.h> #include <errno.h>
#include <unistd.h> #include <unistd.h>
#include <time.h> #include <time.h>
#include <assert.h>
#include "gpgsm.h" #include "gpgsm.h"
#include <gcrypt.h> #include <gcrypt.h>

View File

@ -24,7 +24,6 @@
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
#include <time.h> #include <time.h>
#include <assert.h>
#include "gpgsm.h" #include "gpgsm.h"
#include <gcrypt.h> #include <gcrypt.h>

View File

@ -24,7 +24,6 @@
#include <errno.h> #include <errno.h>
#include <unistd.h> #include <unistd.h>
#include <time.h> #include <time.h>
#include <assert.h>
#include "gpgsm.h" #include "gpgsm.h"
@ -55,7 +54,7 @@ gpgsm_get_fingerprint (ksba_cert_t cert, int algo,
algo = GCRY_MD_SHA1; algo = GCRY_MD_SHA1;
len = gcry_md_get_algo_dlen (algo); len = gcry_md_get_algo_dlen (algo);
assert (len); log_assert (len);
if (!array) if (!array)
array = xmalloc (len); array = xmalloc (len);
@ -67,7 +66,7 @@ gpgsm_get_fingerprint (ksba_cert_t cert, int algo,
{ {
size_t buflen; size_t buflen;
assert (len >= 20); log_assert (len >= 20);
if (!ksba_cert_get_user_data (cert, "sha1-fingerprint", if (!ksba_cert_get_user_data (cert, "sha1-fingerprint",
array, len, &buflen) array, len, &buflen)
&& buflen == 20) && buflen == 20)
@ -115,7 +114,7 @@ gpgsm_get_fingerprint_string (ksba_cert_t cert, int algo)
algo = GCRY_MD_SHA1; algo = GCRY_MD_SHA1;
len = gcry_md_get_algo_dlen (algo); len = gcry_md_get_algo_dlen (algo);
assert (len <= MAX_DIGEST_LEN ); log_assert (len <= MAX_DIGEST_LEN );
gpgsm_get_fingerprint (cert, algo, digest, NULL); gpgsm_get_fingerprint (cert, algo, digest, NULL);
buf = xmalloc (len*3+1); buf = xmalloc (len*3+1);
bin2hexcolon (digest, len, buf); bin2hexcolon (digest, len, buf);
@ -135,7 +134,7 @@ gpgsm_get_fingerprint_hexstring (ksba_cert_t cert, int algo)
algo = GCRY_MD_SHA1; algo = GCRY_MD_SHA1;
len = gcry_md_get_algo_dlen (algo); len = gcry_md_get_algo_dlen (algo);
assert (len <= MAX_DIGEST_LEN ); log_assert (len <= MAX_DIGEST_LEN );
gpgsm_get_fingerprint (cert, algo, digest, NULL); gpgsm_get_fingerprint (cert, algo, digest, NULL);
buf = xmalloc (len*2+1); buf = xmalloc (len*2+1);
bin2hex (digest, len, buf); bin2hex (digest, len, buf);
@ -307,8 +306,8 @@ gpgsm_get_key_algo_info (ksba_cert_t cert, unsigned int *nbits)
} }
/* This is a wrapper around pubkey_algo_string which takesa KSA /* This is a wrapper around pubkey_algo_string which takes a KSBA
* certitificate instead of a Gcrypt public key. Note that this * certificate instead of a Gcrypt public key. Note that this
* function may return NULL on error. */ * function may return NULL on error. */
char * char *
gpgsm_pubkey_algo_string (ksba_cert_t cert, int *r_algoid) gpgsm_pubkey_algo_string (ksba_cert_t cert, int *r_algoid)

View File

@ -23,7 +23,6 @@
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
#include <time.h> #include <time.h>
#include <assert.h>
#include <unistd.h> #include <unistd.h>
#include "gpgsm.h" #include "gpgsm.h"

View File

@ -25,7 +25,6 @@
#include <errno.h> #include <errno.h>
#include <unistd.h> #include <unistd.h>
#include <time.h> #include <time.h>
#include <assert.h>
#include "gpgsm.h" #include "gpgsm.h"
@ -1282,7 +1281,7 @@ list_cert_std (ctrl_t ctrl, ksba_cert_t cert, estream_t fp, int have_secret,
{ {
if (!cert_der) if (!cert_der)
cert_der = ksba_cert_get_image (cert, NULL); cert_der = ksba_cert_get_image (cert, NULL);
assert (cert_der); log_assert (cert_der);
es_fputs (" restriction: ", fp); es_fputs (" restriction: ", fp);
print_utf8_extn (fp, 15, cert_der+off, len); print_utf8_extn (fp, 15, cert_der+off, len);
} }

View File

@ -32,7 +32,6 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <assert.h>
#include <gcrypt.h> #include <gcrypt.h>
#include <errno.h> #include <errno.h>
@ -491,7 +490,7 @@ set_key_iv (gcry_cipher_hd_t chd, char *salt, size_t saltlen, int iter,
unsigned char keybuf[24]; unsigned char keybuf[24];
int rc; int rc;
assert (keybytes == 5 || keybytes == 24); log_assert (keybytes == 5 || keybytes == 24);
if (string_to_key (1, salt, saltlen, iter, pw, keybytes, keybuf)) if (string_to_key (1, salt, saltlen, iter, pw, keybytes, keybuf))
return -1; return -1;
rc = gcry_cipher_setkey (chd, keybuf, keybytes); rc = gcry_cipher_setkey (chd, keybuf, keybytes);
@ -2163,7 +2162,7 @@ build_rsa_key_sequence (gcry_mpi_t *kparms, int mode, size_t *r_length)
} }
plainlen = p - plain; plainlen = p - plain;
assert (needed == plainlen); log_assert (needed == plainlen);
if (!mode) if (!mode)
{ {
@ -2567,7 +2566,7 @@ build_cert_sequence (const unsigned char *buffer, size_t buflen,
size_t certseqlen; size_t certseqlen;
int i; int i;
assert (strlen (keyidstr) == 8); log_assert (strlen (keyidstr) == 8);
/* Walk 8 steps down to collect the info: */ /* Walk 8 steps down to collect the info: */

View File

@ -22,7 +22,6 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <stdarg.h> #include <stdarg.h>
#include <assert.h>
#include <errno.h> #include <errno.h>
#include "gpgsm.h" #include "gpgsm.h"
@ -106,7 +105,7 @@ read_list (char *key, char *country, int *lnr)
listname, *lnr); listname, *lnr);
return gpg_error (GPG_ERR_BAD_DATA); return gpg_error (GPG_ERR_BAD_DATA);
} }
assert (p[i]); log_assert (p[i]);
i++; i++;
while (spacep (p+i)) while (spacep (p+i))
i++; i++;

View File

@ -25,7 +25,6 @@
#include <errno.h> #include <errno.h>
#include <unistd.h> #include <unistd.h>
#include <time.h> #include <time.h>
#include <assert.h>
#include "gpgsm.h" #include "gpgsm.h"
#include <gcrypt.h> #include <gcrypt.h>
@ -808,7 +807,7 @@ gpgsm_sign (ctrl_t ctrl, certlist_t signerlist,
unsigned char *digest; unsigned char *digest;
size_t digest_len; size_t digest_len;
assert (!detached); log_assert (!detached);
rc = hash_and_copy_data (data_fd, data_md, writer); rc = hash_and_copy_data (data_fd, data_md, writer);
if (rc) if (rc)

View File

@ -28,7 +28,6 @@
#include <errno.h> #include <errno.h>
#include <unistd.h> #include <unistd.h>
#include <time.h> #include <time.h>
#include <assert.h>
#include "gpgsm.h" #include "gpgsm.h"
#include <gcrypt.h> #include <gcrypt.h>
@ -363,7 +362,7 @@ gpgsm_verify (ctrl_t ctrl, int in_fd, int data_fd, estream_t out_fp)
} }
else if (gpg_err_code (rc) == GPG_ERR_NO_DATA) else if (gpg_err_code (rc) == GPG_ERR_NO_DATA)
{ {
assert (!msgdigest); log_assert (!msgdigest);
rc = 0; rc = 0;
algoid = NULL; algoid = NULL;
algo = 0; algo = 0;