From 0e960d940a3b52406bb72af2750b6b6d29e39067 Mon Sep 17 00:00:00 2001 From: Marcus Brinkmann Date: Tue, 20 Apr 2010 01:11:35 +0000 Subject: common/ 2010-04-20 Marcus Brinkmann * logging.c (do_log_ignore_arg): New helper function. (log_string): Use it to remove ugly volatile hack that causes gcc warning. (log_flush): Likewise. * sysutils.c (gnupg_unsetenv) [!HAVE_W32CE_SYSTEM]: Return something. (gnupg_setenv) [!HAVE_W32CE_SYSTEM]: Likewise. * pka.c (get_pka_info): Solve strict aliasing rule violation. * t-exechelp.c (test_close_all_fds): Use dummy variables to silence gcc warning. kbx/ 2010-04-20 Marcus Brinkmann * keybox-update.c [!HAVE_DOSISH_SYSTEM]: Include ../common/sysutils.h even then to silence gcc warning about missing declaration of gnupg_remove. tools/ 2010-04-20 Marcus Brinkmann * gpgconf-comp.c (option_check_validity): Use dummy variables to silence gcc warning. --- common/pka.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'common/pka.c') diff --git a/common/pka.c b/common/pka.c index 751ccf7c2..5cdc323e6 100644 --- a/common/pka.c +++ b/common/pka.c @@ -180,7 +180,7 @@ get_pka_info (const char *address, unsigned char *fpr) unsigned char *p, *pend; const char *domain; char *name; - + HEADER header; domain = strrchr (address, '@'); if (!domain || domain == address || !domain[1]) @@ -196,18 +196,24 @@ get_pka_info (const char *address, unsigned char *fpr) xfree (name); if (anslen < sizeof(HEADER)) return NULL; /* DNS resolver returned a too short answer. */ - if ( (rc=((HEADER*)answer)->rcode) != NOERROR ) + + /* Don't despair: A good compiler should optimize this away, as + header is just 32 byte and constant at compile time. It's + one way to comply with strict aliasing rules. */ + memcpy (&header, answer, sizeof (header)); + + if ( (rc=header.rcode) != NOERROR ) return NULL; /* DNS resolver returned an error. */ /* We assume that PACKETSZ is large enough and don't do dynmically expansion of the buffer. */ if (anslen > PACKETSZ) return NULL; /* DNS resolver returned a too long answer */ - - qdcount = ntohs (((HEADER*)answer)->qdcount); - ancount = ntohs (((HEADER*)answer)->ancount); - nscount = ntohs (((HEADER*)answer)->nscount); - arcount = ntohs (((HEADER*)answer)->arcount); + + qdcount = ntohs (header.qdcount); + ancount = ntohs (header.ancount); + nscount = ntohs (header.nscount); + arcount = ntohs (header.arcount); if (!ancount) return NULL; /* Got no answer. */ -- cgit v1.2.3