home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / unix / volume27 / bootp-2.2.B / patch02 < prev    next >
Text File  |  1993-10-19  |  10KB  |  355 lines

  1. Newsgroups: comp.sources.unix
  2. From: gwr@mc.com (Gordon W. Ross)
  3. Subject: v27i077: bootp-2.2 - RFC 1048 "bootp" server (w/ vendor extensions), Patch02
  4. Sender: unix-sources-moderator@gw.home.vix.com
  5. Approved: vixie@gw.home.vix.com
  6.  
  7. Submitted-By: gwr@mc.com (Gordon W. Ross)
  8. Posting-Number: Volume 27, Issue 77
  9. Archive-Name: bootp-2.2.B/patch02
  10.  
  11. Here are fixes for some old bugs caused by references to free memory
  12. that show up when one uses a large bootptab file.  All versions of
  13. bootpd derived from the 2.1 or 2.2 CMU code need this patch.
  14. (I am surprised we did not get bitten by this earlier.)
  15.  
  16. Your copy becomes version 2.2.D after these chages.
  17.  
  18. Note that there is work underway to merge the various 2.2+
  19. versions of bootp into a unified 2.4 version.  The results
  20. will be posted here when we are ready, but if you'd like to
  21. help test version 2.4 please send me some mail.
  22.  
  23. Gordon W. Ross          Mercury Computer Systems
  24. gwr@mc.com              199 Riverneck Road
  25. 508-256-1300            Chelmsford, MA 01824-2820
  26.  
  27. Only in bootp-2.2.D: Announce-2.2.D
  28. diff -rc bootp-2.2.C/bootpd.h bootp-2.2.D/bootpd.h
  29. *** bootp-2.2.C/bootpd.h    Thu Oct  7 15:40:43 1993
  30. --- bootp-2.2.D/bootpd.h    Tue Oct 19 12:09:41 1993
  31. ***************
  32. *** 195,200 ****
  33. --- 195,201 ----
  34.    */
  35.   
  36.   struct host {
  37. +     unsigned            linkcount;        /* hash list inserts */
  38.       struct flag            flags;        /* ALL valid fields */
  39.       struct in_addr_list        *cookie_server,
  40.                   *domain_server,
  41. diff -rc bootp-2.2.C/bootptab bootp-2.2.D/bootptab
  42. *** bootp-2.2.C/bootptab    Fri Oct  8 13:02:26 1993
  43. --- bootp-2.2.D/bootptab    Mon Oct 18 17:36:44 1993
  44. ***************
  45. *** 62,72 ****
  46.   # hosts, but we don't really use this feature at CMU):
  47.   
  48.   # This is for testing the arbitrary tag option:
  49. ! # T14 is the NIS domain name
  50. ! # T15 is the NIS server list
  51.   walnut:tc=subnet16.dummy:ht=ethernet:ha=08.00.20.0E.FF.30:\
  52.       :ip=192.233.16.24:bf=boot.sun4c:\
  53. !     :T14="mc.com":T15=192.233.16.4:
  54.   
  55.   # Tadpole 885 board.
  56.   tp885:tc=subnet17.dummy:ht=ethernet:ha=08.00.4C.00.2F.74:\
  57. --- 62,72 ----
  58.   # hosts, but we don't really use this feature at CMU):
  59.   
  60.   # This is for testing the arbitrary tag option:
  61. ! # T40 is the NIS domain name
  62. ! # T41 is the NIS server list
  63.   walnut:tc=subnet16.dummy:ht=ethernet:ha=08.00.20.0E.FF.30:\
  64.       :ip=192.233.16.24:bf=boot.sun4c:\
  65. !     :T40="mc.com":T41=192.233.16.4:T128="hello":
  66.   
  67.   # Tadpole 885 board.
  68.   tp885:tc=subnet17.dummy:ht=ethernet:ha=08.00.4C.00.2F.74:\
  69. diff -rc bootp-2.2.C/hash.c bootp-2.2.D/hash.c
  70. *** bootp-2.2.C/hash.c    Thu Oct  7 11:37:08 1993
  71. --- bootp-2.2.D/hash.c    Tue Oct 19 12:01:27 1993
  72. ***************
  73. *** 94,114 ****
  74.   
  75.   
  76.   /*
  77. !  * Recursively frees an entire linked list of bucket members (used in the open
  78.    * hashing scheme).  Does nothing if the passed pointer is NULL.
  79.    */
  80.   
  81. ! PRIVATE void hashi_FreeMember(bucketptr, free_data)
  82.   hash_member *bucketptr;
  83.   void (*free_data)();
  84.   {
  85. !     if (bucketptr) {
  86. !     /*
  87. !      * Free next member if necessary
  88. !      */
  89. !     hashi_FreeMember(bucketptr->next, free_data);
  90.       (*free_data)(bucketptr->data);
  91.       free((char *) bucketptr);
  92.       }
  93.   }
  94.   
  95. --- 94,113 ----
  96.   
  97.   
  98.   /*
  99. !  * Frees an entire linked list of bucket members (used in the open
  100.    * hashing scheme).  Does nothing if the passed pointer is NULL.
  101.    */
  102.   
  103. ! PRIVATE void hashi_FreeMembers(bucketptr, free_data)
  104.   hash_member *bucketptr;
  105.   void (*free_data)();
  106.   {
  107. !     hash_member *nextbucket;
  108. !     while (bucketptr) {
  109. !     nextbucket = bucketptr->next;
  110.       (*free_data)(bucketptr->data);
  111.       free((char *) bucketptr);
  112. +     bucketptr = nextbucket;
  113.       }
  114.   }
  115.   
  116. ***************
  117. *** 129,135 ****
  118.   
  119.       bucketptr = hashtable->table;
  120.       for (i = 0; i < hashtable->size; i++) {
  121. !     hashi_FreeMember(*bucketptr, free_data);
  122.       *bucketptr++ = NULL;
  123.       }    
  124.       hashtable->bucketnum = 0;
  125. --- 128,134 ----
  126.   
  127.       bucketptr = hashtable->table;
  128.       for (i = 0; i < hashtable->size; i++) {
  129. !     hashi_FreeMembers(*bucketptr, free_data);
  130.       *bucketptr++ = NULL;
  131.       }    
  132.       hashtable->bucketnum = 0;
  133. ***************
  134. *** 215,236 ****
  135.   int (*compare)();
  136.   hash_datum *key, *element;
  137.   {
  138. !     hash_member *memberptr, *temp;
  139.       
  140.       hashcode %= hashtable->size;
  141.       if (hash_Exists(hashtable, hashcode, compare, key)) {
  142.       return -1;    /* At least one entry already exists */
  143.       }
  144. !     memberptr = (hashtable->table)[hashcode];
  145.       temp = (hash_member *) malloc(sizeof(hash_member));
  146. !     if (temp) {
  147. !     (hashtable->table)[hashcode] = temp;
  148. !     temp->data = element;
  149. !     temp->next = memberptr;
  150. !     return 0;    /* Success */
  151. !     } else {
  152.       return -1;    /* malloc failed! */
  153. !     }
  154.   }
  155.   
  156.   
  157. --- 214,234 ----
  158.   int (*compare)();
  159.   hash_datum *key, *element;
  160.   {
  161. !     hash_member *temp;
  162.       
  163.       hashcode %= hashtable->size;
  164.       if (hash_Exists(hashtable, hashcode, compare, key)) {
  165.       return -1;    /* At least one entry already exists */
  166.       }
  167.       temp = (hash_member *) malloc(sizeof(hash_member));
  168. !     if (!temp)
  169.       return -1;    /* malloc failed! */
  170. !     temp->data = element;
  171. !     temp->next = (hashtable->table)[hashcode];;
  172. !     (hashtable->table)[hashcode] = temp;
  173. !     return 0;    /* Success */
  174.   }
  175.   
  176.   
  177. ***************
  178. *** 263,272 ****
  179.       while (memberptr && (*compare)(key, memberptr->data)) {
  180.       (hashtable->table)[hashcode] = memberptr->next;
  181.       /*
  182. !      * Stop hashi_FreeMember() from recursively deleting the whole list!
  183.        */
  184.       memberptr->next = NULL;
  185. !     hashi_FreeMember(memberptr, free_data);
  186.       memberptr = (hashtable->table)[hashcode];
  187.       retval = 0;
  188.       }
  189. --- 261,270 ----
  190.       while (memberptr && (*compare)(key, memberptr->data)) {
  191.       (hashtable->table)[hashcode] = memberptr->next;
  192.       /*
  193. !      * Stop hashi_FreeMembers() from recursively deleting the whole list!
  194.        */
  195.       memberptr->next = NULL;
  196. !     hashi_FreeMembers(memberptr, free_data);
  197.       memberptr = (hashtable->table)[hashcode];
  198.       retval = 0;
  199.       }
  200. ***************
  201. *** 283,292 ****
  202.           tempptr = memberptr;
  203.           previous->next = memberptr = memberptr->next;
  204.           /*
  205. !          * Put the brakes on hashi_FreeMember(). . . .
  206.            */
  207.           tempptr->next = NULL;
  208. !         hashi_FreeMember(tempptr, free_data);
  209.           retval = 0;
  210.       } else {
  211.           previous = memberptr;
  212. --- 281,290 ----
  213.           tempptr = memberptr;
  214.           previous->next = memberptr = memberptr->next;
  215.           /*
  216. !          * Put the brakes on hashi_FreeMembers(). . . .
  217.            */
  218.           tempptr->next = NULL;
  219. !         hashi_FreeMembers(tempptr, free_data);
  220.           retval = 0;
  221.       } else {
  222.           previous = memberptr;
  223. diff -rc bootp-2.2.C/readfile.c bootp-2.2.D/readfile.c
  224. *** bootp-2.2.C/readfile.c    Thu Oct 14 19:34:13 1993
  225. --- bootp-2.2.D/readfile.c    Tue Oct 19 12:27:05 1993
  226. ***************
  227. *** 301,306 ****
  228. --- 301,308 ----
  229.           break;
  230.       }
  231.       hp = (struct host *) smalloc(sizeof(struct host));
  232. +     bzero((char *)hp, sizeof(*hp));
  233. +     /* the link count it zero */
  234.   
  235.       /*
  236.        * Get individual info
  237. ***************
  238. *** 308,313 ****
  239. --- 310,316 ----
  240.       hp->flags.vm_auto = TRUE;
  241.       bcopy(vm_rfc1048, hp->vm_cookie, 4);
  242.       if (process_entry(hp, buffer) < 0) {
  243. +         hp->linkcount = 1;
  244.           free_host(hp);
  245.           continue;
  246.       }
  247. ***************
  248. *** 316,321 ****
  249. --- 319,326 ----
  250.           nhosts++;
  251.       }
  252.       if (hp->flags.htype && hp->flags.haddr) {
  253. +         /* We will either insert it or free it. */
  254. +         hp->linkcount++;
  255.           hashcode = hash_HashFunction(hp->haddr, haddrlength(hp->htype));
  256.           if (hash_Insert(hwhashtable, hashcode, hwinscmp, hp, hp) < 0) {
  257.           report(LOG_WARNING, "duplicate %s address: %s\n",
  258. ***************
  259. *** 330,345 ****
  260.           if (hash_Insert(iphashtable, hashcode, nullcmp, hp, hp) < 0) {
  261.           report(LOG_ERR,
  262.               "hash_Insert() failed on IP address insertion\n");
  263.           }
  264.       }
  265.   
  266.       hashcode = hash_HashFunction(hp->hostname->string,
  267.                        strlen(hp->hostname->string));
  268. !     if (hash_Insert(nmhashtable, hashcode, nullcmp, hp->hostname->string, hp) < 0) {
  269.           report(LOG_ERR,
  270.              "hash_Insert() failed on insertion of hostname: \"%s\"\n",
  271.              hp->hostname->string);
  272.       }
  273.       nentries++;
  274.       }
  275.   
  276. --- 335,359 ----
  277.           if (hash_Insert(iphashtable, hashcode, nullcmp, hp, hp) < 0) {
  278.           report(LOG_ERR,
  279.               "hash_Insert() failed on IP address insertion\n");
  280. +         } else {
  281. +         /* Just inserted the host struct in a new hash list. */
  282. +         hp->linkcount++;
  283.           }
  284.       }
  285.   
  286.       hashcode = hash_HashFunction(hp->hostname->string,
  287.                        strlen(hp->hostname->string));
  288. !     if (hash_Insert(nmhashtable, hashcode, nullcmp,
  289. !             hp->hostname->string, hp) < 0)
  290. !     {
  291.           report(LOG_ERR,
  292.              "hash_Insert() failed on insertion of hostname: \"%s\"\n",
  293.              hp->hostname->string);
  294. +     } else {
  295. +         /* Just inserted the host struct in a new hash list. */
  296. +         hp->linkcount++;
  297.       }
  298.       nentries++;
  299.       }
  300.   
  301. ***************
  302. *** 1914,1936 ****
  303.   PRIVATE void free_host(hostptr)
  304.   struct host *hostptr;
  305.   {
  306. !     if (hostptr) {
  307. !     del_iplist(hostptr->cookie_server);
  308. !     del_iplist(hostptr->domain_server);
  309. !     del_iplist(hostptr->gateway);
  310. !     del_iplist(hostptr->impress_server);
  311. !     del_iplist(hostptr->log_server);
  312. !     del_iplist(hostptr->lpr_server);
  313. !     del_iplist(hostptr->name_server);
  314. !     del_iplist(hostptr->rlp_server);
  315. !     del_iplist(hostptr->time_server);
  316. !     del_string(hostptr->hostname);
  317. !     del_string(hostptr->homedir);
  318. !     del_string(hostptr->bootfile);
  319. !     del_string(hostptr->tftpdir);
  320. !     del_bindata(hostptr->generic);
  321. !     free((char *) hostptr);
  322. !     }
  323.   }
  324.   
  325.   
  326. --- 1928,1952 ----
  327.   PRIVATE void free_host(hostptr)
  328.   struct host *hostptr;
  329.   {
  330. !     if (hostptr == NULL)
  331. !     return;
  332. !     if (--(hostptr->linkcount))
  333. !     return;
  334. !     del_iplist(hostptr->cookie_server);
  335. !     del_iplist(hostptr->domain_server);
  336. !     del_iplist(hostptr->gateway);
  337. !     del_iplist(hostptr->impress_server);
  338. !     del_iplist(hostptr->log_server);
  339. !     del_iplist(hostptr->lpr_server);
  340. !     del_iplist(hostptr->name_server);
  341. !     del_iplist(hostptr->rlp_server);
  342. !     del_iplist(hostptr->time_server);
  343. !     del_string(hostptr->hostname);
  344. !     del_string(hostptr->homedir);
  345. !     del_string(hostptr->bootfile);
  346. !     del_string(hostptr->tftpdir);
  347. !     del_bindata(hostptr->generic);
  348. !     free((char *) hostptr);
  349.   }
  350.   
  351.   
  352.