1
0
mirror of git://git.gnupg.org/gnupg.git synced 2025-01-23 15:07:03 +01:00

gpg: Assert that an opaque parameter is really what we expect.

* g10/gpg.h (SERVER_CONTROL_MAGIC): New const.
(server_control_s): Add field 'magic'.
* g10/gpg.c (gpg_init_default_ctrl): Init MAGIC.
* g10/import.c (impex_filter_getval): Assert MAGIC.

Signed-off-by: Werner Koch <wk@gnupg.org>
This commit is contained in:
Werner Koch 2017-03-31 20:06:54 +02:00
parent 8f2671d2cc
commit 52ba5e67ca
No known key found for this signature in database
GPG Key ID: E3FDFF218E45B72B
3 changed files with 12 additions and 1 deletions

View File

@ -2182,7 +2182,7 @@ set_compliance_option (enum cmd_and_opt_values option)
static void static void
gpg_init_default_ctrl (ctrl_t ctrl) gpg_init_default_ctrl (ctrl_t ctrl)
{ {
(void)ctrl; ctrl->magic = SERVER_CONTROL_MAGIC;
} }

View File

@ -68,11 +68,20 @@ struct tofu_dbs_s;
typedef struct tofu_dbs_s *tofu_dbs_t; typedef struct tofu_dbs_s *tofu_dbs_t;
#if SIZEOF_UNSIGNED_LONG == 8
# define SERVER_CONTROL_MAGIC 0x53616c696e676572
#else
# define SERVER_CONTROL_MAGIC 0x53616c69
#endif
/* Session control object. This object is passed to most functions to /* Session control object. This object is passed to most functions to
convey the status of a session. Note that the defaults are set by convey the status of a session. Note that the defaults are set by
gpg_init_default_ctrl(). */ gpg_init_default_ctrl(). */
struct server_control_s struct server_control_s
{ {
/* Always has the value SERVER_CONTROL_MAGIC. */
unsigned long magic;
/* Local data for server.c */ /* Local data for server.c */
struct server_local_s *server_local; struct server_local_s *server_local;

View File

@ -1182,6 +1182,8 @@ impex_filter_getval (void *cookie, const char *propname)
static char numbuf[20]; static char numbuf[20];
const char *result; const char *result;
log_assert (ctrl && ctrl->magic == SERVER_CONTROL_MAGIC);
if (node->pkt->pkttype == PKT_USER_ID if (node->pkt->pkttype == PKT_USER_ID
|| node->pkt->pkttype == PKT_ATTRIBUTE) || node->pkt->pkttype == PKT_ATTRIBUTE)
{ {