From b34add3fe438a693e236a835135bd11b4e177daa Mon Sep 17 00:00:00 2001 From: Marcus Brinkmann Date: Thu, 26 May 2011 16:01:26 +0200 Subject: [PATCH] Check context pointers for null pointer on entry points. --- src/ChangeLog | 40 +++++++++++++++++++++++++++++++ src/decrypt-verify.c | 8 +++++++ src/decrypt.c | 8 +++++++ src/delete.c | 8 +++++++ src/edit.c | 15 ++++++++++++ src/encrypt-sign.c | 6 +++++ src/encrypt.c | 8 ++++++- src/export.c | 19 +++++++++++++++ src/genkey.c | 7 ++++++ src/getauditlog.c | 7 ++++++ src/gpgconf.c | 12 ++++++++-- src/gpgme.c | 56 ++++++++++++++++++++++++++++++++++++++++++++ src/import.c | 14 +++++++++++ src/keylist.c | 6 +++++ src/op-support.c | 7 +++++- src/opassuan.c | 9 +++++++ src/passwd.c | 7 ++++++ src/sign.c | 8 +++++++ src/trustlist.c | 4 ++-- src/verify.c | 10 ++++++++ src/vfs-create.c | 6 +++++ src/vfs-mount.c | 7 ++++++ 22 files changed, 266 insertions(+), 6 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index cf5a5efd..3cbc41d4 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,43 @@ +2011-05-26 Marcus Brinkmann + + * decrypt.c (gpgme_op_decrypt_start, gpgme_op_decrypt): Check CTX. + * decrypt-verify.c (gpgme_op_decrypt_verify_start) + (gpgme_op_decrypt_verify): Likewise. + * delete.c (gpgme_op_delete_start, gpgme_op_delete): Likewise. + * edit.c (gpgme_op_edit_start, gpgme_op_edit) + (gpgme_op_card_edit_start, gpgme_op_card_edit): Likewise. + * encrypt.c (gpgme_op_encrypt_start, gpgme_op_encrypt): Likewise. + * encrypt-sign.c (gpgme_op_encrypt_sign_start) + (gpgme_op_encrypt_sign): Likewise. + * export.c (gpgme_op_export_start, gpgme_op_export) + (gpgme_op_export_ext_start, gpgme_op_export_ext) + (gpgme_op_export_keys_start, gpgme_op_export_keys): Likewise. + * genkey.c (gpgme_op_genkey_start, gpgme_op_genkey): Likewise. + * getauditlog.c (gpgme_op_getauditlog_start) + (gpgme_op_getauditlog): Likewise. + * gpgconf.c (gpgme_op_conf_load, gpgme_op_conf_save): Likewise. + * import.c (gpgme_op_import_start, gpgme_op_import_keys_start) + (gpgme_op_import_keys, gpgme_op_import): Likewise. + * keylist.c (gpgme_op_keylist_start, gpgme_op_keylist_ext_start): Likewise. + * opassuan.c (gpgme_op_assuan_transact_start) + (gpgme_op_assuan_transact_ext): Likewise. + * passwd.c (gpgme_op_passwd_start, gpgme_op_passwd): Likewise. + * sign.c (gpgme_op_sign_start, gpgme_op_sign): Likewise. + * trustlist.c (gpgme_op_trustlist_start) + (gpgme_op_trustlist_next): Likewise. + * verify.c (gpgme_op_verify_start, gpgme_get_sig_key): Likewise. + * op-support.c (_gpgme_op_data_lookup): Likewise. + * vfs-create.c (gpgme_op_vfs_transact, gpgme_op_vfs_create): Likewise. + * vfs-mount.c (gpgme_op_vfs_mount, gpgme_op_vfs_transact): Likewise. + * gpgme.c (gpgme_set_protocol) + (gpgme_set_sub_protocol) + (gpgme_set_armor, gpgme_set_include_certs) + (gpgme_set_keylist_mode, gpgme_set_passphrase_cb) + (gpgme_set_progress_cb, gpgme_set_io_cbs, gpgme_set_locale) + (gpgme_ctx_set_engine_info, gpgme_sig_notation_clear): Likewise. + * gpgme.c (gpgme_new): Check for valid R_CTX. + (gpgme_cancel, gpgme_cancel_async, gpgme_release): Likewise. + 2011-04-06 Werner Koch * gpgme-config.in: Add option --host. Change options --cflags and diff --git a/src/decrypt-verify.c b/src/decrypt-verify.c index 87d5223b..a5a751b3 100644 --- a/src/decrypt-verify.c +++ b/src/decrypt-verify.c @@ -91,6 +91,10 @@ gpgme_op_decrypt_verify_start (gpgme_ctx_t ctx, gpgme_data_t cipher, TRACE_BEG2 (DEBUG_CTX, "gpgme_op_decrypt_verify_start", ctx, "cipher=%p, plain=%p", cipher, plain); + + if (!ctx) + return TRACE_ERR (gpg_error (GPG_ERR_INV_VALUE)); + err = decrypt_verify_start (ctx, 0, cipher, plain); return TRACE_ERR (err); } @@ -106,6 +110,10 @@ gpgme_op_decrypt_verify (gpgme_ctx_t ctx, gpgme_data_t cipher, TRACE_BEG2 (DEBUG_CTX, "gpgme_op_decrypt_verify", ctx, "cipher=%p, plain=%p", cipher, plain); + + if (!ctx) + return TRACE_ERR (gpg_error (GPG_ERR_INV_VALUE)); + err = decrypt_verify_start (ctx, 1, cipher, plain); if (!err) err = _gpgme_wait_one (ctx); diff --git a/src/decrypt.c b/src/decrypt.c index c017b907..b74c5081 100644 --- a/src/decrypt.c +++ b/src/decrypt.c @@ -375,6 +375,10 @@ gpgme_op_decrypt_start (gpgme_ctx_t ctx, gpgme_data_t cipher, TRACE_BEG2 (DEBUG_CTX, "gpgme_op_decrypt_start", ctx, "cipher=%p, plain=%p", cipher, plain); + + if (!ctx) + return TRACE_ERR (gpg_error (GPG_ERR_INV_VALUE)); + err = decrypt_start (ctx, 0, cipher, plain); return TRACE_ERR (err); } @@ -389,6 +393,10 @@ gpgme_op_decrypt (gpgme_ctx_t ctx, gpgme_data_t cipher, gpgme_data_t plain) TRACE_BEG2 (DEBUG_CTX, "gpgme_op_decrypt", ctx, "cipher=%p, plain=%p", cipher, plain); + + if (!ctx) + return TRACE_ERR (gpg_error (GPG_ERR_INV_VALUE)); + err = decrypt_start (ctx, 1, cipher, plain); if (!err) err = _gpgme_wait_one (ctx); diff --git a/src/delete.c b/src/delete.c index c5a92f1d..1a501d8e 100644 --- a/src/delete.c +++ b/src/delete.c @@ -100,6 +100,10 @@ gpgme_op_delete_start (gpgme_ctx_t ctx, const gpgme_key_t key, "key=%p (%s), allow_secret=%i", key, (key->subkeys && key->subkeys->fpr) ? key->subkeys->fpr : "invalid", allow_secret); + + if (!ctx) + return TRACE_ERR (gpg_error (GPG_ERR_INV_VALUE)); + err = delete_start (ctx, 0, key, allow_secret); return TRACE_ERR (err); } @@ -116,6 +120,10 @@ gpgme_op_delete (gpgme_ctx_t ctx, const gpgme_key_t key, int allow_secret) "key=%p (%s), allow_secret=%i", key, (key->subkeys && key->subkeys->fpr) ? key->subkeys->fpr : "invalid", allow_secret); + + if (!ctx) + return TRACE_ERR (gpg_error (GPG_ERR_INV_VALUE)); + err = delete_start (ctx, 1, key, allow_secret); if (!err) err = _gpgme_wait_one (ctx); diff --git a/src/edit.c b/src/edit.c index fbdcfdfb..4abf24fa 100644 --- a/src/edit.c +++ b/src/edit.c @@ -145,6 +145,10 @@ gpgme_op_edit_start (gpgme_ctx_t ctx, gpgme_key_t key, "key=%p (%s), fnc=%p fnc_value=%p, out=%p", key, (key->subkeys && key->subkeys->fpr) ? key->subkeys->fpr : "invalid", fnc, fnc_value, out); + + if (!ctx) + return TRACE_ERR (gpg_error (GPG_ERR_INV_VALUE)); + err = edit_start (ctx, 0, 0, key, fnc, fnc_value, out); return err; } @@ -163,6 +167,9 @@ gpgme_op_edit (gpgme_ctx_t ctx, gpgme_key_t key, (key->subkeys && key->subkeys->fpr) ? key->subkeys->fpr : "invalid", fnc, fnc_value, out); + if (!ctx) + return TRACE_ERR (gpg_error (GPG_ERR_INV_VALUE)); + err = edit_start (ctx, 1, 0, key, fnc, fnc_value, out); if (!err) @@ -182,6 +189,10 @@ gpgme_op_card_edit_start (gpgme_ctx_t ctx, gpgme_key_t key, "key=%p (%s), fnc=%p fnc_value=%p, out=%p", key, (key->subkeys && key->subkeys->fpr) ? key->subkeys->fpr : "invalid", fnc, fnc_value, out); + + if (!ctx) + return TRACE_ERR (gpg_error (GPG_ERR_INV_VALUE)); + err = edit_start (ctx, 0, 1, key, fnc, fnc_value, out); return err; } @@ -199,6 +210,10 @@ gpgme_op_card_edit (gpgme_ctx_t ctx, gpgme_key_t key, "key=%p (%s), fnc=%p fnc_value=%p, out=%p", key, (key->subkeys && key->subkeys->fpr) ? key->subkeys->fpr : "invalid", fnc, fnc_value, out); + + if (!ctx) + return TRACE_ERR (gpg_error (GPG_ERR_INV_VALUE)); + err = edit_start (ctx, 1, 1, key, fnc, fnc_value, out); if (!err) err = _gpgme_wait_one (ctx); diff --git a/src/encrypt-sign.c b/src/encrypt-sign.c index 3b862be8..78286004 100644 --- a/src/encrypt-sign.c +++ b/src/encrypt-sign.c @@ -99,6 +99,9 @@ gpgme_op_encrypt_sign_start (gpgme_ctx_t ctx, gpgme_key_t recp[], TRACE_BEG3 (DEBUG_CTX, "gpgme_op_encrypt_sign_start", ctx, "flags=0x%x, plain=%p, cipher=%p", flags, plain, cipher); + + if (!ctx) + return TRACE_ERR (gpg_error (GPG_ERR_INV_VALUE)); if (_gpgme_debug_trace () && recp) { @@ -130,6 +133,9 @@ gpgme_op_encrypt_sign (gpgme_ctx_t ctx, gpgme_key_t recp[], TRACE_BEG3 (DEBUG_CTX, "gpgme_op_encrypt_sign", ctx, "flags=0x%x, plain=%p, cipher=%p", flags, plain, cipher); + + if (!ctx) + return TRACE_ERR (gpg_error (GPG_ERR_INV_VALUE)); if (_gpgme_debug_trace () && recp) { diff --git a/src/encrypt.c b/src/encrypt.c index c9599b5c..641e9004 100644 --- a/src/encrypt.c +++ b/src/encrypt.c @@ -231,6 +231,9 @@ gpgme_op_encrypt_start (gpgme_ctx_t ctx, gpgme_key_t recp[], TRACE_BEG3 (DEBUG_CTX, "gpgme_op_encrypt_start", ctx, "flags=0x%x, plain=%p, cipher=%p", flags, plain, cipher); + + if (!ctx) + return TRACE_ERR (gpg_error (GPG_ERR_INV_VALUE)); if (_gpgme_debug_trace () && recp) { @@ -261,7 +264,10 @@ gpgme_op_encrypt (gpgme_ctx_t ctx, gpgme_key_t recp[], TRACE_BEG3 (DEBUG_CTX, "gpgme_op_encrypt", ctx, "flags=0x%x, plain=%p, cipher=%p", flags, plain, cipher); - + + if (!ctx) + return TRACE_ERR (gpg_error (GPG_ERR_INV_VALUE)); + if (_gpgme_debug_trace () && recp) { int i = 0; diff --git a/src/export.c b/src/export.c index 42f55977..9c1c79c0 100644 --- a/src/export.c +++ b/src/export.c @@ -80,6 +80,10 @@ gpgme_op_export_start (gpgme_ctx_t ctx, const char *pattern, TRACE_BEG3 (DEBUG_CTX, "gpgme_op_export_start", ctx, "pattern=%s, mode=0x%x, keydata=%p", pattern, mode, keydata); + + if (!ctx) + return TRACE_ERR (gpg_error (GPG_ERR_INV_VALUE)); + err = export_start (ctx, 0, pattern, mode, keydata); return TRACE_ERR (err); } @@ -95,6 +99,9 @@ gpgme_op_export (gpgme_ctx_t ctx, const char *pattern, TRACE_BEG3 (DEBUG_CTX, "gpgme_op_export", ctx, "pattern=%s, mode=0x%x, keydata=%p", pattern, mode, keydata); + if (!ctx) + return TRACE_ERR (gpg_error (GPG_ERR_INV_VALUE)); + err = export_start (ctx, 1, pattern, mode, keydata); if (!err) err = _gpgme_wait_one (ctx); @@ -144,6 +151,9 @@ gpgme_op_export_ext_start (gpgme_ctx_t ctx, const char *pattern[], TRACE_BEG2 (DEBUG_CTX, "gpgme_op_export_ext_start", ctx, "mode=0x%x, keydata=%p", mode, keydata); + if (!ctx) + return TRACE_ERR (gpg_error (GPG_ERR_INV_VALUE)); + if (_gpgme_debug_trace () && pattern) { int i = 0; @@ -170,6 +180,9 @@ gpgme_op_export_ext (gpgme_ctx_t ctx, const char *pattern[], TRACE_BEG2 (DEBUG_CTX, "gpgme_op_export_ext_start", ctx, "mode=0x%x, keydata=%p", mode, keydata); + if (!ctx) + return TRACE_ERR (gpg_error (GPG_ERR_INV_VALUE)); + if (_gpgme_debug_trace () && pattern) { int i = 0; @@ -256,6 +269,9 @@ gpgme_op_export_keys_start (gpgme_ctx_t ctx, TRACE_BEG2 (DEBUG_CTX, "gpgme_op_export_keys_start", ctx, "mode=0x%x, keydata=%p", mode, keydata); + + if (!ctx) + return TRACE_ERR (gpg_error (GPG_ERR_INV_VALUE)); if (_gpgme_debug_trace () && keys) { @@ -284,6 +300,9 @@ gpgme_op_export_keys (gpgme_ctx_t ctx, TRACE_BEG2 (DEBUG_CTX, "gpgme_op_export_keys", ctx, "mode=0x%x, keydata=%p", mode, keydata); + + if (!ctx) + return TRACE_ERR (gpg_error (GPG_ERR_INV_VALUE)); if (_gpgme_debug_trace () && keys) { diff --git a/src/genkey.c b/src/genkey.c index 6de3bb8b..bfc7c2af 100644 --- a/src/genkey.c +++ b/src/genkey.c @@ -203,6 +203,10 @@ gpgme_op_genkey_start (gpgme_ctx_t ctx, const char *parms, TRACE_BEG2 (DEBUG_CTX, "gpgme_op_genkey_start", ctx, "pubkey=%p, seckey=%p", pubkey, seckey); TRACE_LOGBUF (parms, strlen (parms)); + + if (!ctx) + return TRACE_ERR (gpg_error (GPG_ERR_INV_VALUE)); + err = genkey_start (ctx, 0, parms, pubkey, seckey); return TRACE_ERR (err); } @@ -221,6 +225,9 @@ gpgme_op_genkey (gpgme_ctx_t ctx, const char *parms, gpgme_data_t pubkey, "pubkey=%p, seckey=%p", pubkey, seckey); TRACE_LOGBUF (parms, strlen (parms)); + if (!ctx) + return TRACE_ERR (gpg_error (GPG_ERR_INV_VALUE)); + err = genkey_start (ctx, 1, parms, pubkey, seckey); if (!err) err = _gpgme_wait_one (ctx); diff --git a/src/getauditlog.c b/src/getauditlog.c index 6bd5cd78..d8435ac5 100644 --- a/src/getauditlog.c +++ b/src/getauditlog.c @@ -67,6 +67,10 @@ gpgme_op_getauditlog_start (gpgme_ctx_t ctx, gpg_error_t err; TRACE_BEG2 (DEBUG_CTX, "gpgme_op_getauditlog_start", ctx, "output=%p, flags=0x%x", output, flags); + + if (!ctx) + return TRACE_ERR (gpg_error (GPG_ERR_INV_VALUE)); + err = getauditlog_start (ctx, 0, output, flags); return TRACE_ERR (err); } @@ -84,6 +88,9 @@ gpgme_op_getauditlog (gpgme_ctx_t ctx, gpgme_data_t output, unsigned int flags) TRACE_BEG2 (DEBUG_CTX, "gpgme_op_getauditlog", ctx, "output=%p, flags=0x%x", output, flags); + if (!ctx) + return TRACE_ERR (gpg_error (GPG_ERR_INV_VALUE)); + err = getauditlog_start (ctx, 1, output, flags); if (!err) err = _gpgme_wait_one (ctx); diff --git a/src/gpgconf.c b/src/gpgconf.c index 3c9d16b5..f3411d51 100644 --- a/src/gpgconf.c +++ b/src/gpgconf.c @@ -94,8 +94,12 @@ gpgme_op_conf_load (gpgme_ctx_t ctx, gpgme_conf_comp_t *conf_p) { #ifdef ENABLE_GPGCONF gpgme_error_t err; - gpgme_protocol_t proto = ctx->protocol; + gpgme_protocol_t proto; + if (!ctx) + return gpg_error (GPG_ERR_INV_VALUE); + + proto = ctx->protocol; ctx->protocol = GPGME_PROTOCOL_GPGCONF; err = _gpgme_op_reset (ctx, 1); if (err) @@ -116,8 +120,12 @@ gpgme_op_conf_save (gpgme_ctx_t ctx, gpgme_conf_comp_t comp) { #ifdef ENABLE_GPGCONF gpgme_error_t err; - gpgme_protocol_t proto = ctx->protocol; + gpgme_protocol_t proto; + if (!ctx) + return gpg_error (GPG_ERR_INV_VALUE); + + proto = ctx->protocol; ctx->protocol = GPGME_PROTOCOL_GPGCONF; err = _gpgme_op_reset (ctx, 1); if (err) diff --git a/src/gpgme.c b/src/gpgme.c index 7feb3be9..c8e6a8b7 100644 --- a/src/gpgme.c +++ b/src/gpgme.c @@ -63,6 +63,9 @@ gpgme_new (gpgme_ctx_t *r_ctx) if (_gpgme_selftest) return TRACE_ERR (gpgme_error (_gpgme_selftest)); + if (!r_ctx) + return TRACE_ERR (gpg_error (GPG_ERR_INV_VALUE)); + ctx = calloc (1, sizeof *ctx); if (!ctx) return TRACE_ERR (gpg_error_from_errno (errno)); @@ -160,6 +163,9 @@ gpgme_cancel (gpgme_ctx_t ctx) TRACE_BEG (DEBUG_CTX, "gpgme_cancel", ctx); + if (!ctx) + return TRACE_ERR (gpg_error (GPG_ERR_INV_VALUE)); + err = _gpgme_cancel_with_err (ctx, gpg_error (GPG_ERR_CANCELED), 0); return TRACE_ERR (err); @@ -172,6 +178,9 @@ gpgme_cancel_async (gpgme_ctx_t ctx) { TRACE_BEG (DEBUG_CTX, "gpgme_cancel_async", ctx); + if (!ctx) + return TRACE_ERR (gpg_error (GPG_ERR_INV_VALUE)); + LOCK (ctx->lock); ctx->canceled = 1; UNLOCK (ctx->lock); @@ -186,6 +195,9 @@ gpgme_release (gpgme_ctx_t ctx) { TRACE (DEBUG_CTX, "gpgme_release", ctx); + if (!ctx) + return; + _gpgme_engine_release (ctx->engine); _gpgme_fd_table_deinit (&ctx->fdt); _gpgme_release_result (ctx); @@ -278,6 +290,9 @@ gpgme_set_protocol (gpgme_ctx_t ctx, gpgme_protocol_t protocol) && protocol != GPGME_PROTOCOL_UISERVER) return TRACE_ERR (gpg_error (GPG_ERR_INV_VALUE)); + if (!ctx) + return TRACE_ERR (gpg_error (GPG_ERR_INV_VALUE)); + if (ctx->protocol != protocol) { /* Shut down the engine when switching protocols. */ @@ -301,6 +316,7 @@ gpgme_get_protocol (gpgme_ctx_t ctx) "ctx->protocol=%i (%s)", ctx->protocol, gpgme_get_protocol_name (ctx->protocol) ? gpgme_get_protocol_name (ctx->protocol) : "invalid"); + return ctx->protocol; } @@ -311,6 +327,10 @@ gpgme_set_sub_protocol (gpgme_ctx_t ctx, gpgme_protocol_t protocol) TRACE2 (DEBUG_CTX, "gpgme_set_sub_protocol", ctx, "protocol=%i (%s)", protocol, gpgme_get_protocol_name (protocol) ? gpgme_get_protocol_name (protocol) : "invalid"); + + if (!ctx) + return gpg_error (GPG_ERR_INV_VALUE); + ctx->sub_protocol = protocol; return 0; } @@ -323,6 +343,7 @@ gpgme_get_sub_protocol (gpgme_ctx_t ctx) "ctx->sub_protocol=%i (%s)", ctx->sub_protocol, gpgme_get_protocol_name (ctx->sub_protocol) ? gpgme_get_protocol_name (ctx->sub_protocol) : "invalid"); + return ctx->sub_protocol; } @@ -367,6 +388,10 @@ gpgme_set_armor (gpgme_ctx_t ctx, int use_armor) { TRACE2 (DEBUG_CTX, "gpgme_set_armor", ctx, "use_armor=%i (%s)", use_armor, use_armor ? "yes" : "no"); + + if (!ctx) + return; + ctx->use_armor = use_armor; } @@ -390,6 +415,10 @@ gpgme_set_textmode (gpgme_ctx_t ctx, int use_textmode) { TRACE2 (DEBUG_CTX, "gpgme_set_textmode", ctx, "use_textmode=%i (%s)", use_textmode, use_textmode ? "yes" : "no"); + + if (!ctx) + return; + ctx->use_textmode = use_textmode; } @@ -409,6 +438,9 @@ gpgme_get_textmode (gpgme_ctx_t ctx) void gpgme_set_include_certs (gpgme_ctx_t ctx, int nr_of_certs) { + if (!ctx) + return; + if (nr_of_certs == GPGME_INCLUDE_CERTS_DEFAULT) ctx->include_certs = GPGME_INCLUDE_CERTS_DEFAULT; else if (nr_of_certs < -2) @@ -441,6 +473,9 @@ gpgme_set_keylist_mode (gpgme_ctx_t ctx, gpgme_keylist_mode_t mode) TRACE1 (DEBUG_CTX, "gpgme_set_keylist_mode", ctx, "keylist_mode=0x%x", mode); + if (!ctx) + return gpg_error (GPG_ERR_INV_VALUE); + ctx->keylist_mode = mode; return 0; } @@ -464,6 +499,10 @@ gpgme_set_passphrase_cb (gpgme_ctx_t ctx, gpgme_passphrase_cb_t cb, { TRACE2 (DEBUG_CTX, "gpgme_set_passphrase_cb", ctx, "passphrase_cb=%p/%p", cb, cb_value); + + if (!ctx) + return; + ctx->passphrase_cb = cb; ctx->passphrase_cb_value = cb_value; } @@ -492,6 +531,10 @@ gpgme_set_progress_cb (gpgme_ctx_t ctx, gpgme_progress_cb_t cb, void *cb_value) { TRACE2 (DEBUG_CTX, "gpgme_set_progress_cb", ctx, "progress_cb=%p/%p", cb, cb_value); + + if (!ctx) + return; + ctx->progress_cb = cb; ctx->progress_cb_value = cb_value; } @@ -516,6 +559,9 @@ gpgme_get_progress_cb (gpgme_ctx_t ctx, gpgme_progress_cb_t *r_cb, void gpgme_set_io_cbs (gpgme_ctx_t ctx, gpgme_io_cbs_t io_cbs) { + if (!ctx) + return; + if (io_cbs) { TRACE6 (DEBUG_CTX, "gpgme_set_io_cbs", ctx, @@ -593,6 +639,9 @@ gpgme_set_locale (gpgme_ctx_t ctx, int category, const char *value) TRACE_BEG2 (DEBUG_CTX, "gpgme_set_locale", ctx, "category=%i, value=%s", category, value ? value : "(null)"); + if (!ctx) + return TRACE_ERR (gpg_error (GPG_ERR_INV_VALUE)); + #define PREPARE_ONE_LOCALE(lcat, ucat) \ if (!failed && value \ && (category == LC_ALL || category == LC_ ## ucat)) \ @@ -678,6 +727,9 @@ gpgme_ctx_set_engine_info (gpgme_ctx_t ctx, gpgme_protocol_t proto, ? gpgme_get_protocol_name (proto) : "unknown", file_name ? file_name : "(default)", home_dir ? home_dir : "(default)"); + + if (!ctx) + return TRACE_ERR (gpg_error (GPG_ERR_INV_VALUE)); /* Shut down the engine when changing engine info. */ if (ctx->engine) @@ -715,6 +767,10 @@ void gpgme_sig_notation_clear (gpgme_ctx_t ctx) { TRACE (DEBUG_CTX, "gpgme_sig_notation_clear", ctx); + + if (!ctx) + return; + _gpgme_sig_notation_clear (ctx); } diff --git a/src/import.c b/src/import.c index 784ce165..3bc74413 100644 --- a/src/import.c +++ b/src/import.c @@ -289,6 +289,9 @@ gpgme_op_import_start (gpgme_ctx_t ctx, gpgme_data_t keydata) TRACE_BEG1 (DEBUG_CTX, "gpgme_op_import_start", ctx, "keydata=%p", keydata); + if (!ctx) + return TRACE_ERR (gpg_error (GPG_ERR_INV_VALUE)); + err = _gpgme_op_import_start (ctx, 0, keydata); return TRACE_ERR (err); } @@ -303,6 +306,9 @@ gpgme_op_import (gpgme_ctx_t ctx, gpgme_data_t keydata) TRACE_BEG1 (DEBUG_CTX, "gpgme_op_import", ctx, "keydata=%p", keydata); + if (!ctx) + return TRACE_ERR (gpg_error (GPG_ERR_INV_VALUE)); + err = _gpgme_op_import_start (ctx, 1, keydata); if (!err) err = _gpgme_wait_one (ctx); @@ -365,6 +371,10 @@ gpgme_op_import_keys_start (gpgme_ctx_t ctx, gpgme_key_t *keys) gpg_error_t err; TRACE_BEG (DEBUG_CTX, "gpgme_op_import_keys_start", ctx); + + if (!ctx) + return TRACE_ERR (gpg_error (GPG_ERR_INV_VALUE)); + if (_gpgme_debug_trace () && keys) { int i = 0; @@ -400,6 +410,10 @@ gpgme_op_import_keys (gpgme_ctx_t ctx, gpgme_key_t *keys) gpgme_error_t err; TRACE_BEG (DEBUG_CTX, "gpgme_op_import_keys", ctx); + + if (!ctx) + return TRACE_ERR (gpg_error (GPG_ERR_INV_VALUE)); + if (_gpgme_debug_trace () && keys) { int i = 0; diff --git a/src/keylist.c b/src/keylist.c index 8f61a261..29e30a0f 100644 --- a/src/keylist.c +++ b/src/keylist.c @@ -863,6 +863,9 @@ gpgme_op_keylist_start (gpgme_ctx_t ctx, const char *pattern, int secret_only) TRACE_BEG2 (DEBUG_CTX, "gpgme_op_keylist_start", ctx, "pattern=%s, secret_only=%i", pattern, secret_only); + if (!ctx) + return TRACE_ERR (gpg_error (GPG_ERR_INV_VALUE)); + err = _gpgme_op_reset (ctx, 2); if (err) return TRACE_ERR (err); @@ -900,6 +903,9 @@ gpgme_op_keylist_ext_start (gpgme_ctx_t ctx, const char *pattern[], TRACE_BEG2 (DEBUG_CTX, "gpgme_op_keylist_ext_start", ctx, "secret_only=%i, reserved=0x%x", secret_only, reserved); + if (!ctx) + return TRACE_ERR (gpg_error (GPG_ERR_INV_VALUE)); + err = _gpgme_op_reset (ctx, 2); if (err) return TRACE_ERR (err); diff --git a/src/op-support.c b/src/op-support.c index 0a5639be..000560bb 100644 --- a/src/op-support.c +++ b/src/op-support.c @@ -37,7 +37,12 @@ gpgme_error_t _gpgme_op_data_lookup (gpgme_ctx_t ctx, ctx_op_data_id_t type, void **hook, int size, void (*cleanup) (void *)) { - struct ctx_op_data *data = ctx->op_data; + struct ctx_op_data *data; + + if (!ctx) + return gpg_error (GPG_ERR_INV_VALUE); + + data = ctx->op_data; while (data && data->type != type) data = data->next; if (!data) diff --git a/src/opassuan.c b/src/opassuan.c index bd50089b..21c25cab 100644 --- a/src/opassuan.c +++ b/src/opassuan.c @@ -95,6 +95,9 @@ gpgme_op_assuan_transact_start (gpgme_ctx_t ctx, command, data_cb, data_cb_value, inq_cb, inq_cb_value, status_cb, status_cb_value); + if (!ctx) + return TRACE_ERR (gpg_error (GPG_ERR_INV_VALUE)); + err = opassuan_start (ctx, 0, command, data_cb, data_cb_value, inq_cb, inq_cb_value, status_cb, status_cb_value); return TRACE_ERR (err); @@ -122,6 +125,9 @@ gpgme_op_assuan_transact_ext (gpgme_ctx_t ctx, command, data_cb, data_cb_value, inq_cb, inq_cb_value, status_cb, status_cb_value, op_err_p); + if (!ctx) + return TRACE_ERR (gpg_error (GPG_ERR_INV_VALUE)); + err = opassuan_start (ctx, 1, command, data_cb, data_cb_value, inq_cb, inq_cb_value, @@ -212,6 +218,9 @@ gpgme_op_assuan_transact (gpgme_ctx_t ctx, TRACE (DEBUG_CTX, "gpgme_op_assuan_transact", ctx); + if (!ctx) + return gpg_error (GPG_ERR_INV_VALUE); + /* Users of the old-style session based interfaces need to look at the result structure. */ err = gpgme_op_assuan_transact_ext (ctx, command, data_cb, data_cb_value, diff --git a/src/passwd.c b/src/passwd.c index ab61b4a4..97b69603 100644 --- a/src/passwd.c +++ b/src/passwd.c @@ -157,6 +157,10 @@ gpgme_op_passwd_start (gpgme_ctx_t ctx, gpgme_key_t key, unsigned int flags) gpg_error_t err; TRACE_BEG2 (DEBUG_CTX, "gpgme_op_passwd_start", ctx, "key=%p, flags=0x%x", key, flags); + + if (!ctx) + return TRACE_ERR (gpg_error (GPG_ERR_INV_VALUE)); + err = passwd_start (ctx, 0, key, flags); return TRACE_ERR (err); } @@ -172,6 +176,9 @@ gpgme_op_passwd (gpgme_ctx_t ctx, gpgme_key_t key, unsigned int flags) TRACE_BEG2 (DEBUG_CTX, "gpgme_op_passwd", ctx, "key=%p, flags=0x%x", key, flags); + if (!ctx) + return TRACE_ERR (gpg_error (GPG_ERR_INV_VALUE)); + err = passwd_start (ctx, 1, key, flags); if (!err) err = _gpgme_wait_one (ctx); diff --git a/src/sign.c b/src/sign.c index 8aff542e..2f308a06 100644 --- a/src/sign.c +++ b/src/sign.c @@ -393,6 +393,10 @@ gpgme_op_sign_start (gpgme_ctx_t ctx, gpgme_data_t plain, gpgme_data_t sig, gpg_error_t err; TRACE_BEG3 (DEBUG_CTX, "gpgme_op_sign_start", ctx, "plain=%p, sig=%p, mode=%i", plain, sig, mode); + + if (!ctx) + return TRACE_ERR (gpg_error (GPG_ERR_INV_VALUE)); + err = sign_start (ctx, 0, plain, sig, mode); return TRACE_ERR (err); } @@ -407,6 +411,10 @@ gpgme_op_sign (gpgme_ctx_t ctx, gpgme_data_t plain, gpgme_data_t sig, TRACE_BEG3 (DEBUG_CTX, "gpgme_op_sign", ctx, "plain=%p, sig=%p, mode=%i", plain, sig, mode); + + if (!ctx) + return TRACE_ERR (gpg_error (GPG_ERR_INV_VALUE)); + err = sign_start (ctx, 1, plain, sig, mode); if (!err) err = _gpgme_wait_one (ctx); diff --git a/src/trustlist.c b/src/trustlist.c index 67c724fb..a96b6c72 100644 --- a/src/trustlist.c +++ b/src/trustlist.c @@ -177,7 +177,7 @@ gpgme_op_trustlist_start (gpgme_ctx_t ctx, const char *pattern, int max_level) TRACE_BEG2 (DEBUG_CTX, "gpgme_op_trustlist_start", ctx, "pattern=%s, max_level=%i", pattern, max_level); - if (!pattern || !*pattern) + if (!ctx || !pattern || !*pattern) return TRACE_ERR (gpg_error (GPG_ERR_INV_VALUE)); err = _gpgme_op_reset (ctx, 2); @@ -212,7 +212,7 @@ gpgme_op_trustlist_next (gpgme_ctx_t ctx, gpgme_trust_item_t *r_item) TRACE_BEG (DEBUG_CTX, "gpgme_op_trustlist_next", ctx); - if (!r_item) + if (!ctx || !r_item) return TRACE_ERR (gpg_error (GPG_ERR_INV_VALUE)); *r_item = NULL; if (!ctx) diff --git a/src/verify.c b/src/verify.c index ed81b8ac..a8f67124 100644 --- a/src/verify.c +++ b/src/verify.c @@ -836,6 +836,10 @@ gpgme_op_verify_start (gpgme_ctx_t ctx, gpgme_data_t sig, TRACE_BEG3 (DEBUG_CTX, "gpgme_op_verify_start", ctx, "sig=%p, signed_text=%p, plaintext=%p", sig, signed_text, plaintext); + + if (!ctx) + return TRACE_ERR (gpg_error (GPG_ERR_INV_VALUE)); + err = verify_start (ctx, 0, sig, signed_text, plaintext); return TRACE_ERR (err); } @@ -853,6 +857,9 @@ gpgme_op_verify (gpgme_ctx_t ctx, gpgme_data_t sig, gpgme_data_t signed_text, "sig=%p, signed_text=%p, plaintext=%p", sig, signed_text, plaintext); + if (!ctx) + return TRACE_ERR (gpg_error (GPG_ERR_INV_VALUE)); + err = verify_start (ctx, 1, sig, signed_text, plaintext); if (!err) err = _gpgme_wait_one (ctx); @@ -870,6 +877,9 @@ gpgme_get_sig_key (gpgme_ctx_t ctx, int idx, gpgme_key_t *r_key) gpgme_verify_result_t result; gpgme_signature_t sig; + if (!ctx) + return gpg_error (GPG_ERR_INV_VALUE); + result = gpgme_op_verify_result (ctx); sig = result->signatures; diff --git a/src/vfs-create.c b/src/vfs-create.c index d7fd24f1..e8dab472 100644 --- a/src/vfs-create.c +++ b/src/vfs-create.c @@ -90,6 +90,9 @@ gpgme_op_vfs_transact (gpgme_ctx_t ctx, gpgme_error_t *op_err) { gpgme_error_t err; + + if (!ctx) + return gpg_error (GPG_ERR_INV_VALUE); err = vfs_start (ctx, 1, command, data_cb, data_cb_value, inq_cb, inq_cb_value, status_cb, status_cb_value); @@ -178,6 +181,9 @@ gpgme_op_vfs_create (gpgme_ctx_t ctx, gpgme_key_t recp[], "container_file=%s, flags=0x%x, op_err=%p", container_file, flags, op_err); + if (!ctx) + return TRACE_ERR (gpg_error (GPG_ERR_INV_VALUE)); + if (_gpgme_debug_trace () && recp) { int i = 0; diff --git a/src/vfs-mount.c b/src/vfs-mount.c index b9136895..327e3531 100644 --- a/src/vfs-mount.c +++ b/src/vfs-mount.c @@ -147,6 +147,9 @@ gpgme_op_vfs_transact (gpgme_ctx_t ctx, gpgme_error_t *op_err) { gpgme_error_t err; + + if (!ctx) + return gpg_error (GPG_ERR_INV_VALUE); err = vfs_start (ctx, 1, command, data_cb, data_cb_value, inq_cb, inq_cb_value, status_cb, status_cb_value); @@ -232,6 +235,10 @@ gpgme_op_vfs_mount (gpgme_ctx_t ctx, const char *container_file, TRACE_BEG4 (DEBUG_CTX, "gpgme_op_vfs_mount", ctx, "container=%s, mount_dir=%s, flags=0x%x, op_err=%p", container_file, mount_dir, flags, op_err); + + if (!ctx) + return TRACE_ERR (gpg_error (GPG_ERR_INV_VALUE)); + err = _gpgme_op_vfs_mount (ctx, container_file, mount_dir, flags, op_err); return TRACE_ERR (err); }