openbsd-ports/net/cvsync/patches/patch-cvsyncd_access_c
sthen a13880e19f Initialize sa->sa_socket / sa_config earlier in access_authorize(). Seems to
fix crashes in cvsyncd now made visible by malloc's junk-after-free default.

From patrick keshishian who says 'I think protocol_exchange() will eventually
"realize" that status and/or error are not ok, and will return false, and
server thread will call assess_done(), which will socket_close() and
config_revoke().' Thanks for looking into this and suggesting the diff.

Survived 24h+ on my server, and looks good to naddy.
2014-11-19 23:49:41 +00:00

69 lines
1.9 KiB
Plaintext

$OpenBSD: patch-cvsyncd_access_c,v 1.2 2014/11/19 23:49:41 sthen Exp $
--- cvsyncd/access.c.orig Mon Jul 18 07:33:02 2005
+++ cvsyncd/access.c Mon Nov 17 23:35:16 2014
@@ -103,10 +103,12 @@ static pthread_mutex_t mtx = PTHREAD_MUTEX_INITIALIZER
bool
access_init(size_t sz)
{
+#if defined(NO_ARC4RANDOM)
#if !defined(NO_INITSTATE)
static char acl_random_state[256];
#endif /* !defined(NO_INITSTATE) */
struct timeval tv;
+#endif /* defined(NO_ARC4RANDOM) */
if ((acl = malloc(sz * sizeof(*acl))) == NULL) {
logmsg_err("ACL: %s", strerror(errno));
@@ -119,6 +121,7 @@ access_init(size_t sz)
return (false);
}
+#if defined(NO_ARC4RANDOM)
(void)gettimeofday(&tv, NULL);
#if !defined(NO_INITSTATE)
@@ -127,6 +130,7 @@ access_init(size_t sz)
#else /* !defined(NO_INITSTATE) */
srandom((unsigned long)tv.tv_usec);
#endif /* !defined(NO_INITSTATE) */
+#endif /* defined(NO_ARC4RANDOM) */
acl_name[0] = '\0';
acl_size = sz;
@@ -193,6 +197,11 @@ access_authorize(int sock, struct config *cf)
}
sa->sa_error = CVSYNC_NO_ERROR;
+ sa->sa_socket = sock;
+ sa->sa_config = cf;
+
+ config_acquire(cf);
+
if (cvsync_isinterrupted()) {
sa->sa_status = ACL_DENY;
sa->sa_error = CVSYNC_ERROR_UNAVAIL;
@@ -205,7 +214,11 @@ access_authorize(int sock, struct config *cf)
sa->sa_error = CVSYNC_ERROR_UNAVAIL;
return (sa);
}
+#if !defined(NO_ARC4RANDOM)
+ _v.v32 = arc4random();
+#else /* !defined(NO_ARC4RANDOM) */
_v.v32 = (uint32_t)random();
+#endif /* !defined(NO_ARC4RANDOM) */
wn = snprintf(sa->sa_hostinfo, sizeof(sa->sa_hostinfo),
"[%s] (%02x%02x%02x%02x)", sa->sa_addr,
_v.v8[0], _v.v8[1], _v.v8[2], _v.v8[3]);
@@ -305,11 +318,6 @@ access_authorize(int sock, struct config *cf)
sa->sa_error = CVSYNC_ERROR_UNAVAIL;
return (sa);
}
-
- sa->sa_socket = sock;
- sa->sa_config = cf;
-
- config_acquire(cf);
logmsg("%s Connected (status=%d)", sa->sa_hostinfo, sa->sa_status);
time(&sa->sa_tick);