1
0
mirror of git://git.gnupg.org/gnupg.git synced 2024-12-22 10:19:57 +01:00

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

View File

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

View File

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

View File

@ -27,7 +27,6 @@
#include <errno.h>
#include <unistd.h>
#include <time.h>
#include <assert.h>
#include "gpgsm.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++] = 1; /* block type */
i = nframe - len - asnlen -3 ;
assert ( i > 1 );
log_assert ( i > 1 );
memset ( frame+n, 0xff, i ); n += i;
frame[n++] = 0;
memcpy ( frame+n, asn, asnlen ); n += asnlen;
memcpy ( frame+n, gcry_md_read(md, algo), len ); n += len;
assert ( n == nframe );
log_assert ( n == nframe );
}
if (DBG_CRYPTO)
{

View File

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

View File

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

View File

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

View File

@ -59,7 +59,6 @@
#include <errno.h>
#include <unistd.h>
#include <time.h>
#include <assert.h>
#include "gpgsm.h"
#include <gcrypt.h>
@ -448,7 +447,7 @@ proc_parameters (ctrl_t ctrl, struct para_data_s *para,
char *cardkeyid = NULL;
/* 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
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++)
{
len = strlen (s);
assert (len);
log_assert (len);
snprintf (numbuf, DIM(numbuf), "%u:", (unsigned int)len);
buf = p = xtrymalloc (11 + strlen (numbuf) + len + 3);
if (!buf)
@ -942,7 +941,7 @@ create_request (ctrl_t ctrl,
for (seq=0; (s = get_parameter_value (para, pNAMEURI, seq)); seq++)
{
len = strlen (s);
assert (len);
log_assert (len);
snprintf (numbuf, DIM(numbuf), "%u:", (unsigned int)len);
buf = p = xtrymalloc (6 + strlen (numbuf) + len + 3);
if (!buf)
@ -1322,6 +1321,10 @@ create_request (ctrl_t ctrl,
size_t qlen, derlen;
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);
if (err)
{

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -25,7 +25,6 @@
#include <errno.h>
#include <unistd.h>
#include <time.h>
#include <assert.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)
cert_der = ksba_cert_get_image (cert, NULL);
assert (cert_der);
log_assert (cert_der);
es_fputs (" restriction: ", fp);
print_utf8_extn (fp, 15, cert_der+off, len);
}

View File

@ -32,7 +32,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <gcrypt.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];
int rc;
assert (keybytes == 5 || keybytes == 24);
log_assert (keybytes == 5 || keybytes == 24);
if (string_to_key (1, salt, saltlen, iter, pw, keybytes, keybuf))
return -1;
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;
assert (needed == plainlen);
log_assert (needed == plainlen);
if (!mode)
{
@ -2567,7 +2566,7 @@ build_cert_sequence (const unsigned char *buffer, size_t buflen,
size_t certseqlen;
int i;
assert (strlen (keyidstr) == 8);
log_assert (strlen (keyidstr) == 8);
/* Walk 8 steps down to collect the info: */

View File

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

View File

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

View File

@ -28,7 +28,6 @@
#include <errno.h>
#include <unistd.h>
#include <time.h>
#include <assert.h>
#include "gpgsm.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)
{
assert (!msgdigest);
log_assert (!msgdigest);
rc = 0;
algoid = NULL;
algo = 0;