Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/netbsd-2]: src/usr.sbin/rpc.statd Pullup rev 1.25 (requested by bouyer i...



details:   https://anonhg.NetBSD.org/src/rev/7781f3ba80fb
branches:  netbsd-2
changeset: 564368:7781f3ba80fb
user:      jmc <jmc%NetBSD.org@localhost>
date:      Wed Dec 14 03:52:38 2005 +0000

description:
Pullup rev 1.25 (requested by bouyer in ticket #10171)

        We can't call db->put() with key or data pointing back to db(3)'s memory
space, or the database will be corrupted (noticed when the database is
updated in reset_host()). Change change_host() to copy hostname and HostInfo
to local storage before calling db->put().
Change notify_one() to use change_host() instead of calling db->put()
directly.

diffstat:

 usr.sbin/rpc.statd/statd.c |  31 +++++++++++++------------------
 1 files changed, 13 insertions(+), 18 deletions(-)

diffs (77 lines):

diff -r 398d2587cd33 -r 7781f3ba80fb usr.sbin/rpc.statd/statd.c
--- a/usr.sbin/rpc.statd/statd.c        Mon Dec 12 11:26:35 2005 +0000
+++ b/usr.sbin/rpc.statd/statd.c        Wed Dec 14 03:52:38 2005 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: statd.c,v 1.23.4.1 2005/10/28 03:43:13 jmc Exp $       */
+/*     $NetBSD: statd.c,v 1.23.4.2 2005/12/14 03:52:38 jmc Exp $       */
 
 /*
  * Copyright (c) 1997 Christos Zoulas. All rights reserved.
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: statd.c,v 1.23.4.1 2005/10/28 03:43:13 jmc Exp $");
+__RCSID("$NetBSD: statd.c,v 1.23.4.2 2005/12/14 03:52:38 jmc Exp $");
 #endif
 
 /* main() function for status monitor daemon.  Some of the code in this        */
@@ -241,12 +241,17 @@
  *
  */
 void
-change_host(hostname, hp)
-       char *hostname;
+change_host(hostnamep, hp)
+       char *hostnamep;
        HostInfo *hp;
 {
        DBT key, data;
        char *ptr;
+       char hostname[MAXHOSTNAMELEN + 1];
+       HostInfo h;
+
+       strncpy(hostname, hostnamep, MAXHOSTNAMELEN + 1);
+       h = *hp;
 
        for (ptr = hostname; *ptr; ptr++)
                if (isupper((unsigned char) *ptr))
@@ -254,8 +259,8 @@
 
        key.data = hostname;
        key.size = ptr - hostname + 1;
-       data.data = hp;
-       data.size = sizeof(*hp);
+       data.data = &h;
+       data.size = sizeof(h);
 
        switch ((*db->put)(db, &key, &data, 0)) {
        case -1:
@@ -458,7 +463,6 @@
 {
        time_t now = *(time_t *) ptr;
        char *name = key->data;
-       DBT data;
        int error;
 
        if (hi->notifyReqd == 0 || hi->notifyReqd > now)
@@ -495,17 +499,8 @@
                else
                        hi->notifyReqd += 60 * 60;
        }
-       data.data = hi;
-       data.size = sizeof(*hi);
-       switch ((*db->put)(db, key, &data, 0)) {
-       case -1:
-               syslog(LOG_ERR, "Error storing %s (%m)", name);
-       case 0:
-               return error;
-
-       default:
-               abort();
-       }
+       change_host(name, hi);
+       return error;
 }
 
 /* init_file -------------------------------------------------------------- */



Home | Main Index | Thread Index | Old Index