Fix possible system freeze on Mac OS X.

This commit is contained in:
Werner Koch 2009-05-19 22:39:45 +00:00
parent 98f10d74b8
commit 4fa261f8ec
14 changed files with 73 additions and 28 deletions

3
NEWS
View File

@ -24,7 +24,8 @@ Noteworthy changes in version 2.0.12 (not released)
* The gpg-protect-tool now uses gpg-agent via libassuan. Under
Windows the Pinentry will now be put into the foreground.
* Changed code to avoid a possible Mac OS X system freeze.
Noteworthy changes in version 2.0.11 (2009-03-03)
-------------------------------------------------

View File

@ -1,3 +1,8 @@
2009-05-19 Werner Koch <wk@g10code.com>
* gpg-agent.c (JNLIB_NEED_AFLOCAL): Define.
(create_server_socket): Use SUN_LEN macro.
2009-05-15 Werner Koch <wk@g10code.com>
Fix bug #1053.

View File

@ -39,6 +39,7 @@
#include <pth.h>
#define JNLIB_NEED_LOG_LOGV
#define JNLIB_NEED_AFLOCAL
#include "agent.h"
#include <assuan.h> /* Malloc hooks and socket wrappers. */
@ -1457,9 +1458,7 @@ create_server_socket (char *name, int is_ssh, assuan_sock_nonce_t *nonce)
agent_exit (2);
}
strcpy (serv_addr->sun_path, name);
len = (offsetof (struct sockaddr_un, sun_path)
+ strlen (serv_addr->sun_path) + 1);
len = SUN_LEN (serv_addr);
rc = assuan_sock_bind (fd, (struct sockaddr*) serv_addr, len);
if (use_standard_socket && rc == -1 && errno == EADDRINUSE)
{

View File

@ -1,3 +1,8 @@
2009-05-19 Werner Koch <wk@g10code.com>
* simple-pwquery.c (agent_open): Use SUN_LEN
(JNLIB_NEED_AFLOCAL): Define and include mischelp.h.
2009-05-07 Werner Koch <wk@g10code.com>
* sexputil.c (get_rsa_pk_from_canon_sexp): New.

View File

@ -39,6 +39,9 @@
#ifdef HAVE_LOCALE_H
#include <locale.h>
#endif
#define JNLIB_NEED_AFLOCAL
#include "../jnlib/mischelp.h"
#ifdef HAVE_W32_SYSTEM
#include "../jnlib/w32-afunix.h"
#endif
@ -379,8 +382,7 @@ agent_open (int *rfd)
memset (&client_addr, 0, sizeof client_addr);
client_addr.sun_family = AF_UNIX;
strcpy (client_addr.sun_path, infostr);
len = (offsetof (struct sockaddr_un, sun_path)
+ strlen(client_addr.sun_path) + 1);
len = SUN_LEN (&client_addr);
#ifdef HAVE_W32_SYSTEM
rc = _w32_sock_connect (fd, (struct sockaddr*)&client_addr, len );

View File

@ -56,7 +56,4 @@ void gnupg_allow_set_foregound_window (pid_t pid);
#endif /*HAVE_W32_SYSTEM*/
#endif /*GNUPG_COMMON_SYSUTILS_H*/

View File

@ -1,3 +1,8 @@
2009-05-19 Werner Koch <wk@g10code.com>
* mischelp.h: Define PF_LOCAL, AF_LOCAL and SUN_LEN if requested.
* logging.c (fun_writer): Use SUN_LEN to fix a Mac OS X freeze.
2009-03-25 Werner Koch <wk@g10code.com>
* logging.c (fun_closer): Never close fd 2.

View File

@ -39,6 +39,7 @@
#define JNLIB_NEED_LOG_LOGV 1
#define JNLIB_NEED_AFLOCAL 1
#include "libjnlib-config.h"
#include "logging.h"
@ -152,8 +153,7 @@ fun_writer (void *cookie_arg, const char *buffer, my_funopen_hook_size_t size)
addr.sun_family = PF_LOCAL;
strncpy (addr.sun_path, cookie->name, sizeof (addr.sun_path)-1);
addr.sun_path[sizeof (addr.sun_path)-1] = 0;
addrlen = (offsetof (struct sockaddr_un, sun_path)
+ strlen (addr.sun_path) + 1);
addrlen = SUN_LEN (&addr);
if (connect (cookie->fd, (struct sockaddr *) &addr, addrlen) == -1)
{

View File

@ -1,6 +1,6 @@
/* mischelp.h - Miscellaneous helper macros and functions
* Copyright (C) 1999, 2000, 2001, 2002, 2003,
* 2006, 2007 Free Software Foundation, Inc.
* 2006, 2007, 2009 Free Software Foundation, Inc.
*
* This file is part of JNLIB.
*
@ -60,5 +60,35 @@ time_t timegm (struct tm *tm);
#define wipememory(_ptr,_len) wipememory2(_ptr,0,_len)
/* Include hacks which are mainly required for Slowaris. */
#if defined(JNLIB_NEED_AFLOCAL) && !defined(HAVE_W32_SYSTEM)
#include <sys/socket.h>
#include <sys/un.h>
#ifndef PF_LOCAL
# ifdef PF_UNIX
# define PF_LOCAL PF_UNIX
# else
# define PF_LOCAL AF_UNIX
# endif
#endif /*PF_LOCAL*/
#ifndef AF_LOCAL
# define AF_LOCAL AF_UNIX
#endif /*AF_UNIX*/
/* We used to avoid this macro in GnuPG and inlined the AF_LOCAL name
length computation directly with the little twist of adding 1 extra
byte. It seems that this was needed once on an old HP/UX box and
there are also rumours that 4.3 Reno and DEC systems need it. This
one-off buglet did not harm any current system until it came to Mac
OS X where the kernel (as of May 2009) exhibited a strange bug: The
systems basically froze in the connect call if the passed name
contained an invalid directory part. Ignore the old Unices. */
#ifndef SUN_LEN
# define SUN_LEN(ptr) ((size_t) (((struct sockaddr_un *) 0)->sun_path) \
+ strlen ((ptr)->sun_path))
#endif /*SUN_LEN*/
#endif /*JNLIB_NEED_AFLOCAL && !HAVE_W32_SYSTEM*/
#endif /*LIBJNLIB_MISCHELP_H*/

View File

@ -1,3 +1,8 @@
2009-05-19 Werner Koch <wk@g10code.com>
* scdaemon.c (create_server_socket): Use SUN_LEN.
(JNLIB_NEED_AFLOCAL): Define.
2009-05-13 Werner Koch <wk@g10code.com>
* ccid-driver.c (abort_cmd): Add arg SEQNO and change callers.

View File

@ -38,6 +38,7 @@
#include <pth.h>
#define JNLIB_NEED_LOG_LOGV
#define JNLIB_NEED_AFLOCAL
#include "scdaemon.h"
#include <ksba.h>
#include <gcrypt.h>
@ -1032,8 +1033,7 @@ create_server_socket (int is_standard_name, const char *name,
serv_addr->sun_family = AF_UNIX;
assert (strlen (name) + 1 < sizeof (serv_addr->sun_path));
strcpy (serv_addr->sun_path, name);
len = (offsetof (struct sockaddr_un, sun_path)
+ strlen (serv_addr->sun_path) + 1);
len = SUN_LEN (serv_addr);
rc = assuan_sock_bind (fd, (struct sockaddr*) serv_addr, len);
if (is_standard_name && rc == -1 && errno == EADDRINUSE)

View File

@ -1,3 +1,8 @@
2009-05-19 Werner Koch <wk@g10code.com>
* watchgnupg.c: Include jnlib/mischelp.h if required.
(main): Use SUN_LEN.
2009-04-17 Werner Koch <wk@g10code.com>
* ccidmon.c: New.

View File

@ -86,7 +86,6 @@ create_server_socket (const char *filename, int *new_sock)
name.sun_family = AF_LOCAL;
strncpy (name.sun_path, filename, sizeof (name.sun_path));
name.sun_path[sizeof (name.sun_path) - 1] = '\0';
size = SUN_LEN (&name);
remove (filename);

View File

@ -35,7 +35,7 @@
#define PGM "watchgnupg"
/* Allow for a standalone build. */
/* Allow for a standalone build on most systems. */
#ifdef VERSION
#define MYVERSION_LINE PGM " (GnuPG) " VERSION
#define BUGREPORT_LINE "\nReport bugs to <bug-gnupg@gnu.org>.\n"
@ -43,16 +43,9 @@
#define MYVERSION_LINE PGM
#define BUGREPORT_LINE ""
#endif
#ifndef PF_LOCAL
# ifdef PF_UNIX
# define PF_LOCAL PF_UNIX
# else
# define PF_LOCAL AF_UNIX
# endif
# ifndef AF_LOCAL
# define AF_LOCAL AF_UNIX
# endif
#if !defined(SUN_LEN) || !defined(PF_LOCAL) || !defined(AF_LOCAL)
#define JNLIB_NEED_AFLOCAL
#include "../jnlib/mischelp.h"
#endif
@ -285,8 +278,7 @@ main (int argc, char **argv)
srvr_addr.sun_family = AF_LOCAL;
strncpy (srvr_addr.sun_path, *argv, sizeof (srvr_addr.sun_path) - 1);
srvr_addr.sun_path[sizeof (srvr_addr.sun_path) - 1] = 0;
addrlen = (offsetof (struct sockaddr_un, sun_path)
+ strlen (srvr_addr.sun_path) + 1);
addrlen = SUN_LEN (&srvr_addr);
again: