View | Details | Raw Unified | Return to bug 65501 | Differences between
and this patch

Collapse All | Expand All

(-)patch-ai (-19 / +24 lines)
Lines 1-22 Link Here
1
--- db.c.orig	Sat Sep 30 19:39:58 2000
1
--- db.c.orig	Sat Sep 30 19:39:58 2000
2
+++ db.c	Mon Mar 29 14:26:14 2004
2
+++ db.c	Tue Apr 13 14:39:50 2004
3
@@ -41,6 +41,7 @@
3
@@ -41,6 +41,7 @@
4
 #include <string.h>
4
 #include <string.h>
5
 #include <syslog.h>
5
 #include <syslog.h>
6
 #include <unistd.h>
6
 #include <unistd.h>
7
+#include <pthread.h>
7
+#include <pthread.h>
8
8
9
 #include "gnuc.h"
9
 #include "gnuc.h"
10
 #ifdef HAVE_OS_PROTO_H
10
 #ifdef HAVE_OS_PROTO_H
11
@@ -54,18 +55,9 @@
11
@@ -54,18 +55,9 @@
12
 #include "report.h"
12
 #include "report.h"
13
 #include "util.h"
13
 #include "util.h"
14
14
15
-#define HASHSIZE (2 << 15)
15
-#define HASHSIZE (2 << 15)
16
-
16
-
17
 #define NEWACTIVITY_DELTA (6*30*24*60*60)	/* 6 months in seconds */
17
 #define NEWACTIVITY_DELTA (6*30*24*60*60)	/* 6 months in seconds */
18
 #define FLIPFLIP_DELTA (24*60*60)		/* 24 hours in seconds */
18
 #define FLIPFLIP_DELTA (24*60*60)		/* 24 hours in seconds */
19
19
20
-/* Ethernet info */
20
-/* Ethernet info */
21
-struct einfo {
21
-struct einfo {
22
-	u_char e[6];		/* ether address */
22
-	u_char e[6];		/* ether address */
Lines 30-36 Link Here
30
@@ -78,22 +70,69 @@
30
@@ -78,22 +70,69 @@
31
 /* Address hash table */
31
 /* Address hash table */
32
 static struct ainfo ainfo_table[HASHSIZE];
32
 static struct ainfo ainfo_table[HASHSIZE];
33
33
34
+
34
+
35
+/* Ethernet hash table */
35
+/* Ethernet hash table */
36
+struct einfo einfo_table[HASHSIZE];
36
+struct einfo einfo_table[HASHSIZE];
Lines 44-50 Link Here
44
+static struct einfo *einfo_find(u_char *);
44
+static struct einfo *einfo_find(u_char *);
45
 static void check_hname(struct ainfo *);
45
 static void check_hname(struct ainfo *);
46
 struct ainfo *newainfo(void);
46
 struct ainfo *newainfo(void);
47
47
48
+pthread_mutex_t mtx_einfo, mtx_ainfo;
48
+pthread_mutex_t mtx_einfo, mtx_ainfo;
49
+
49
+
50
 int
50
 int
Lines 75-81 Link Here
75
+		  BCOPY(e, ep->e, sizeof(ep->e));
75
+		  BCOPY(e, ep->e, sizeof(ep->e));
76
+		  if (h == NULL)
76
+		  if (h == NULL)
77
+		    h = getsname(a);
77
+		    h = getsname(a);
78
+		  if (h != NULL && !isdigit((int)*h))
78
+		  if (h != NULL)
79
+		    strncpy(ep->h, h, sizeof(ep->h));
79
+		    strncpy(ep->h, h, sizeof(ep->h));
80
+		  ep->t = t;
80
+		  ep->t = t;
81
+		  strncpy(ep->iface, interface, sizeof(ep->iface));
81
+		  strncpy(ep->iface, interface, sizeof(ep->iface));
Lines 97-103 Link Here
97
+
97
+
98
+	pthread_mutex_unlock(&mtx_einfo);
98
+	pthread_mutex_unlock(&mtx_einfo);
99
+	pthread_mutex_lock(&mtx_ainfo);
99
+	pthread_mutex_lock(&mtx_ainfo);
100
100
101
 	/* Lookup ip address */
101
 	/* Lookup ip address */
102
 	ap = ainfo_find(a);
102
 	ap = ainfo_find(a);
103
@@ -101,28 +140,30 @@
103
@@ -101,28 +140,30 @@
Lines 117-123 Link Here
117
-			return (1);
117
-			return (1);
118
 		}
118
 		}
119
 	}
119
 	}
120
120
121
 	/* Check for a virgin ainfo record */
121
 	/* Check for a virgin ainfo record */
122
 	if (ap->ecount == 0) {
122
 	if (ap->ecount == 0) {
123
 		ap->ecount = 1;
123
 		ap->ecount = 1;
Lines 129-135 Link Here
129
+		e2 = NULL;
129
+		e2 = NULL;
130
+		t2 = 0;
130
+		t2 = 0;
131
 	}
131
 	}
132
132
133
 	/* Check for a flip-flop */
133
 	/* Check for a flip-flop */
134
 	if (ap->ecount > 1) {
134
 	if (ap->ecount > 1) {
135
 		ep = ap->elist[1];
135
 		ep = ap->elist[1];
Lines 160-166 Link Here
160
-			return (1);
160
-			return (1);
161
 		}
161
 		}
162
 	}
162
 	}
163
163
164
 	for (i = 2; i < ap->ecount; ++i) {
164
 	for (i = 2; i < ap->ecount; ++i) {
165
 		ep = ap->elist[i];
165
 		ep = ap->elist[i];
166
-		if (MEMCMP(e, ep->e, 6) == 0) {
166
-		if (MEMCMP(e, ep->e, 6) == 0) {
Lines 180-186 Link Here
180
-			return (1);
180
-			return (1);
181
 		}
181
 		}
182
 	}
182
 	}
183
183
184
-	/* New ether address */
184
-	/* New ether address */
185
-	e2 = ap->elist[0]->e;
185
-	e2 = ap->elist[0]->e;
186
-	t2 = ap->elist[0]->t;
186
-	t2 = ap->elist[0]->t;
Lines 230-236 Link Here
230
+
230
+
231
+	return(NULL);
231
+	return(NULL);
232
 }
232
 }
233
233
234
 static struct ainfo *
234
 static struct ainfo *
235
@@ -259,7 +328,7 @@
235
@@ -259,7 +328,7 @@
236
 /* Allocate and initialize a elist struct */
236
 /* Allocate and initialize a elist struct */
Lines 242-256 Link Here
242
 	register struct einfo *ep;
242
 	register struct einfo *ep;
243
 	register u_int size;
243
 	register u_int size;
244
@@ -280,12 +349,16 @@
244
@@ -280,12 +349,16 @@
245
245
246
 	ep = elist++;
246
 	ep = elist++;
247
 	--eleft;
247
 	--eleft;
248
-	BCOPY(e, ep->e, 6);
248
-	BCOPY(e, ep->e, 6);
249
+	BCOPY(e, ep->e, sizeof(ep->e));
249
+	BCOPY(e, ep->e, sizeof(ep->e));
250
 	if (h == NULL && !initializing)
250
 	if (h == NULL && !initializing)
251
 		h = getsname(a);
251
 		h = getsname(a);
252
 	if (h != NULL && !isdigit((int)*h))
252
-	if (h != NULL && !isdigit((int)*h))
253
-		strcpy(ep->h, h);
253
-		strcpy(ep->h, h);
254
+	if (h != NULL)
254
+		strncpy(ep->h, h, sizeof(ep->h));
255
+		strncpy(ep->h, h, sizeof(ep->h));
255
 	ep->t = t;
256
 	ep->t = t;
256
+
257
+
Lines 259-271 Link Here
259
+
260
+
260
 	return (ep);
261
 	return (ep);
261
 }
262
 }
262
263
263
@@ -304,7 +377,7 @@
264
@@ -301,10 +374,10 @@
264
 	if (!isdigit((int)*h) && strcmp(h, ep->h) != 0) {
265
 		return;
266
 	ep = ap->elist[0];
267
 	h = getsname(ap->a);
268
-	if (!isdigit((int)*h) && strcmp(h, ep->h) != 0) {
269
+	if (h != NULL && strcmp(h, ep->h) != 0) {
265
 		syslog(LOG_INFO, "hostname changed %s %s %s -> %s",
270
 		syslog(LOG_INFO, "hostname changed %s %s %s -> %s",
266
 		    intoa(ap->a), e2str(ep->e), ep->h, h);
271
 		    intoa(ap->a), e2str(ep->e), ep->h, h);
267
-		strcpy(ep->h, h);
272
-		strcpy(ep->h, h);
268
+		strncpy(ep->h, h, sizeof(ep->h));
273
+		strncpy(ep->h, h, sizeof(ep->h));
269
 	}
274
 	}
270
 }
275
 }
271
276

Return to bug 65501