home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso
/
unix
/
volume27
/
bootp-2.2.B
/
patch02
< prev
next >
Wrap
Text File
|
1993-10-19
|
10KB
|
355 lines
Newsgroups: comp.sources.unix
From: gwr@mc.com (Gordon W. Ross)
Subject: v27i077: bootp-2.2 - RFC 1048 "bootp" server (w/ vendor extensions), Patch02
Sender: unix-sources-moderator@gw.home.vix.com
Approved: vixie@gw.home.vix.com
Submitted-By: gwr@mc.com (Gordon W. Ross)
Posting-Number: Volume 27, Issue 77
Archive-Name: bootp-2.2.B/patch02
Here are fixes for some old bugs caused by references to free memory
that show up when one uses a large bootptab file. All versions of
bootpd derived from the 2.1 or 2.2 CMU code need this patch.
(I am surprised we did not get bitten by this earlier.)
Your copy becomes version 2.2.D after these chages.
Note that there is work underway to merge the various 2.2+
versions of bootp into a unified 2.4 version. The results
will be posted here when we are ready, but if you'd like to
help test version 2.4 please send me some mail.
Gordon W. Ross Mercury Computer Systems
gwr@mc.com 199 Riverneck Road
508-256-1300 Chelmsford, MA 01824-2820
Only in bootp-2.2.D: Announce-2.2.D
diff -rc bootp-2.2.C/bootpd.h bootp-2.2.D/bootpd.h
*** bootp-2.2.C/bootpd.h Thu Oct 7 15:40:43 1993
--- bootp-2.2.D/bootpd.h Tue Oct 19 12:09:41 1993
***************
*** 195,200 ****
--- 195,201 ----
*/
struct host {
+ unsigned linkcount; /* hash list inserts */
struct flag flags; /* ALL valid fields */
struct in_addr_list *cookie_server,
*domain_server,
diff -rc bootp-2.2.C/bootptab bootp-2.2.D/bootptab
*** bootp-2.2.C/bootptab Fri Oct 8 13:02:26 1993
--- bootp-2.2.D/bootptab Mon Oct 18 17:36:44 1993
***************
*** 62,72 ****
# hosts, but we don't really use this feature at CMU):
# This is for testing the arbitrary tag option:
! # T14 is the NIS domain name
! # T15 is the NIS server list
walnut:tc=subnet16.dummy:ht=ethernet:ha=08.00.20.0E.FF.30:\
:ip=192.233.16.24:bf=boot.sun4c:\
! :T14="mc.com":T15=192.233.16.4:
# Tadpole 885 board.
tp885:tc=subnet17.dummy:ht=ethernet:ha=08.00.4C.00.2F.74:\
--- 62,72 ----
# hosts, but we don't really use this feature at CMU):
# This is for testing the arbitrary tag option:
! # T40 is the NIS domain name
! # T41 is the NIS server list
walnut:tc=subnet16.dummy:ht=ethernet:ha=08.00.20.0E.FF.30:\
:ip=192.233.16.24:bf=boot.sun4c:\
! :T40="mc.com":T41=192.233.16.4:T128="hello":
# Tadpole 885 board.
tp885:tc=subnet17.dummy:ht=ethernet:ha=08.00.4C.00.2F.74:\
diff -rc bootp-2.2.C/hash.c bootp-2.2.D/hash.c
*** bootp-2.2.C/hash.c Thu Oct 7 11:37:08 1993
--- bootp-2.2.D/hash.c Tue Oct 19 12:01:27 1993
***************
*** 94,114 ****
/*
! * Recursively frees an entire linked list of bucket members (used in the open
* hashing scheme). Does nothing if the passed pointer is NULL.
*/
! PRIVATE void hashi_FreeMember(bucketptr, free_data)
hash_member *bucketptr;
void (*free_data)();
{
! if (bucketptr) {
! /*
! * Free next member if necessary
! */
! hashi_FreeMember(bucketptr->next, free_data);
(*free_data)(bucketptr->data);
free((char *) bucketptr);
}
}
--- 94,113 ----
/*
! * Frees an entire linked list of bucket members (used in the open
* hashing scheme). Does nothing if the passed pointer is NULL.
*/
! PRIVATE void hashi_FreeMembers(bucketptr, free_data)
hash_member *bucketptr;
void (*free_data)();
{
! hash_member *nextbucket;
! while (bucketptr) {
! nextbucket = bucketptr->next;
(*free_data)(bucketptr->data);
free((char *) bucketptr);
+ bucketptr = nextbucket;
}
}
***************
*** 129,135 ****
bucketptr = hashtable->table;
for (i = 0; i < hashtable->size; i++) {
! hashi_FreeMember(*bucketptr, free_data);
*bucketptr++ = NULL;
}
hashtable->bucketnum = 0;
--- 128,134 ----
bucketptr = hashtable->table;
for (i = 0; i < hashtable->size; i++) {
! hashi_FreeMembers(*bucketptr, free_data);
*bucketptr++ = NULL;
}
hashtable->bucketnum = 0;
***************
*** 215,236 ****
int (*compare)();
hash_datum *key, *element;
{
! hash_member *memberptr, *temp;
hashcode %= hashtable->size;
if (hash_Exists(hashtable, hashcode, compare, key)) {
return -1; /* At least one entry already exists */
}
! memberptr = (hashtable->table)[hashcode];
temp = (hash_member *) malloc(sizeof(hash_member));
! if (temp) {
! (hashtable->table)[hashcode] = temp;
! temp->data = element;
! temp->next = memberptr;
! return 0; /* Success */
! } else {
return -1; /* malloc failed! */
! }
}
--- 214,234 ----
int (*compare)();
hash_datum *key, *element;
{
! hash_member *temp;
hashcode %= hashtable->size;
if (hash_Exists(hashtable, hashcode, compare, key)) {
return -1; /* At least one entry already exists */
}
!
temp = (hash_member *) malloc(sizeof(hash_member));
! if (!temp)
return -1; /* malloc failed! */
!
! temp->data = element;
! temp->next = (hashtable->table)[hashcode];;
! (hashtable->table)[hashcode] = temp;
! return 0; /* Success */
}
***************
*** 263,272 ****
while (memberptr && (*compare)(key, memberptr->data)) {
(hashtable->table)[hashcode] = memberptr->next;
/*
! * Stop hashi_FreeMember() from recursively deleting the whole list!
*/
memberptr->next = NULL;
! hashi_FreeMember(memberptr, free_data);
memberptr = (hashtable->table)[hashcode];
retval = 0;
}
--- 261,270 ----
while (memberptr && (*compare)(key, memberptr->data)) {
(hashtable->table)[hashcode] = memberptr->next;
/*
! * Stop hashi_FreeMembers() from recursively deleting the whole list!
*/
memberptr->next = NULL;
! hashi_FreeMembers(memberptr, free_data);
memberptr = (hashtable->table)[hashcode];
retval = 0;
}
***************
*** 283,292 ****
tempptr = memberptr;
previous->next = memberptr = memberptr->next;
/*
! * Put the brakes on hashi_FreeMember(). . . .
*/
tempptr->next = NULL;
! hashi_FreeMember(tempptr, free_data);
retval = 0;
} else {
previous = memberptr;
--- 281,290 ----
tempptr = memberptr;
previous->next = memberptr = memberptr->next;
/*
! * Put the brakes on hashi_FreeMembers(). . . .
*/
tempptr->next = NULL;
! hashi_FreeMembers(tempptr, free_data);
retval = 0;
} else {
previous = memberptr;
diff -rc bootp-2.2.C/readfile.c bootp-2.2.D/readfile.c
*** bootp-2.2.C/readfile.c Thu Oct 14 19:34:13 1993
--- bootp-2.2.D/readfile.c Tue Oct 19 12:27:05 1993
***************
*** 301,306 ****
--- 301,308 ----
break;
}
hp = (struct host *) smalloc(sizeof(struct host));
+ bzero((char *)hp, sizeof(*hp));
+ /* the link count it zero */
/*
* Get individual info
***************
*** 308,313 ****
--- 310,316 ----
hp->flags.vm_auto = TRUE;
bcopy(vm_rfc1048, hp->vm_cookie, 4);
if (process_entry(hp, buffer) < 0) {
+ hp->linkcount = 1;
free_host(hp);
continue;
}
***************
*** 316,321 ****
--- 319,326 ----
nhosts++;
}
if (hp->flags.htype && hp->flags.haddr) {
+ /* We will either insert it or free it. */
+ hp->linkcount++;
hashcode = hash_HashFunction(hp->haddr, haddrlength(hp->htype));
if (hash_Insert(hwhashtable, hashcode, hwinscmp, hp, hp) < 0) {
report(LOG_WARNING, "duplicate %s address: %s\n",
***************
*** 330,345 ****
if (hash_Insert(iphashtable, hashcode, nullcmp, hp, hp) < 0) {
report(LOG_ERR,
"hash_Insert() failed on IP address insertion\n");
}
}
hashcode = hash_HashFunction(hp->hostname->string,
strlen(hp->hostname->string));
! if (hash_Insert(nmhashtable, hashcode, nullcmp, hp->hostname->string, hp) < 0) {
report(LOG_ERR,
"hash_Insert() failed on insertion of hostname: \"%s\"\n",
hp->hostname->string);
}
nentries++;
}
--- 335,359 ----
if (hash_Insert(iphashtable, hashcode, nullcmp, hp, hp) < 0) {
report(LOG_ERR,
"hash_Insert() failed on IP address insertion\n");
+ } else {
+ /* Just inserted the host struct in a new hash list. */
+ hp->linkcount++;
}
}
hashcode = hash_HashFunction(hp->hostname->string,
strlen(hp->hostname->string));
! if (hash_Insert(nmhashtable, hashcode, nullcmp,
! hp->hostname->string, hp) < 0)
! {
report(LOG_ERR,
"hash_Insert() failed on insertion of hostname: \"%s\"\n",
hp->hostname->string);
+ } else {
+ /* Just inserted the host struct in a new hash list. */
+ hp->linkcount++;
}
+
nentries++;
}
***************
*** 1914,1936 ****
PRIVATE void free_host(hostptr)
struct host *hostptr;
{
! if (hostptr) {
! del_iplist(hostptr->cookie_server);
! del_iplist(hostptr->domain_server);
! del_iplist(hostptr->gateway);
! del_iplist(hostptr->impress_server);
! del_iplist(hostptr->log_server);
! del_iplist(hostptr->lpr_server);
! del_iplist(hostptr->name_server);
! del_iplist(hostptr->rlp_server);
! del_iplist(hostptr->time_server);
! del_string(hostptr->hostname);
! del_string(hostptr->homedir);
! del_string(hostptr->bootfile);
! del_string(hostptr->tftpdir);
! del_bindata(hostptr->generic);
! free((char *) hostptr);
! }
}
--- 1928,1952 ----
PRIVATE void free_host(hostptr)
struct host *hostptr;
{
! if (hostptr == NULL)
! return;
! if (--(hostptr->linkcount))
! return;
! del_iplist(hostptr->cookie_server);
! del_iplist(hostptr->domain_server);
! del_iplist(hostptr->gateway);
! del_iplist(hostptr->impress_server);
! del_iplist(hostptr->log_server);
! del_iplist(hostptr->lpr_server);
! del_iplist(hostptr->name_server);
! del_iplist(hostptr->rlp_server);
! del_iplist(hostptr->time_server);
! del_string(hostptr->hostname);
! del_string(hostptr->homedir);
! del_string(hostptr->bootfile);
! del_string(hostptr->tftpdir);
! del_bindata(hostptr->generic);
! free((char *) hostptr);
}