home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume7 / patch2 / patch6 / text0000.txt < prev   
Encoding:
Text File  |  1987-01-05  |  4.7 KB  |  160 lines

  1. System: patch version 2.0
  2. Patch #: 6
  3. Priority: HIGH
  4. Subject: New-style context diffs can cause double call to free().
  5. From: lwall@sdcrdcf (Larry Wall)
  6.  
  7. Description:
  8.     When either the pattern section or the replacement section of
  9.     a hunk is omitted, patch copies the corresponding line from
  10.     the other section.  It does this by copying the pointer, not
  11.     by copying the line, so when the hunk is later freed, some
  12.     lines are freed twice.  This gives heartburn to many varieties
  13.     of the malloc package.
  14.  
  15. Fix:    From rn, say "| patch -d DIR", where DIR is your patch source
  16.     directory.  Outside of rn, say "cd DIR; patch <thisarticle".
  17.     If you don't have the patch program, apply the following by hand,
  18.     or get patch.
  19.  
  20.     If patch indicates that patchlevel is the wrong version, you may need
  21.     to apply one or more previous patches, or the patch may already
  22.     have been applied.  See the patchlevel.h file to find out what has or
  23.     has not been applied.  In any event, don't continue with the patch.
  24.  
  25.     If you are missing previous patches they can be obtained from me:
  26.  
  27.     Larry Wall
  28.     {allegra,burdvax,cbosgd,hplabs,ihnp4,sdcsvax}!sdcrdcf!lwall
  29.  
  30.     If you send a mail message of the following form it will greatly speed
  31.     processing:
  32.  
  33.     Subject: Command
  34.     @SH mailpatch PATH patch 2.0 LIST
  35.            ^ note the c
  36.  
  37.     where PATH is a return path FROM ME TO YOU in bang notation, and LIST
  38.     is the number of one or more patches you need, separated by spaces,
  39.     commas, and/or hyphens.  Saying 35- says everything from 35 to the end.
  40.  
  41. Index: patchlevel.h
  42. Prereq: 5
  43. 1c1
  44. < #define PATCHLEVEL 5
  45. ---
  46. > #define PATCHLEVEL 6
  47.  
  48. Index: pch.c
  49. Prereq: 2.0.1.3
  50. *** pch.c.old    Mon Jan  5 17:03:02 1987
  51. *** pch.c    Mon Jan  5 17:03:26 1987
  52. ***************
  53. *** 1,4
  54. ! /* $Header: pch.c,v 2.0.1.3 86/11/14 10:08:33 lwall Exp $
  55.    *
  56.    * $Log:    pch.c,v $
  57.    * Revision 2.0.1.3  86/11/14  10:08:33  lwall
  58.  
  59. --- 1,4 -----
  60. ! /* $Header: pch.c,v 2.0.1.4 87/01/05 16:59:53 lwall Exp $
  61.    *
  62.    * $Log:    pch.c,v $
  63.    * Revision 2.0.1.4  87/01/05  16:59:53  lwall
  64. ***************
  65. *** 1,6
  66.   /* $Header: pch.c,v 2.0.1.3 86/11/14 10:08:33 lwall Exp $
  67.    *
  68.    * $Log:    pch.c,v $
  69.    * Revision 2.0.1.3  86/11/14  10:08:33  lwall
  70.    * Fixed problem where a long pattern wouldn't grow the hunk.
  71.    * Also restored p_input_line when backtracking so error messages are right.
  72.  
  73. --- 1,9 -----
  74.   /* $Header: pch.c,v 2.0.1.4 87/01/05 16:59:53 lwall Exp $
  75.    *
  76.    * $Log:    pch.c,v $
  77. +  * Revision 2.0.1.4  87/01/05  16:59:53  lwall
  78. +  * New-style context diffs caused double call to free().
  79. +  * 
  80.    * Revision 2.0.1.3  86/11/14  10:08:33  lwall
  81.    * Fixed problem where a long pattern wouldn't grow the hunk.
  82.    * Also restored p_input_line when backtracking so error messages are right.
  83. ***************
  84. *** 40,45
  85.   static int p_indent;            /* indent to patch */
  86.   static LINENUM p_base;            /* where to intuit this time */
  87.   static LINENUM p_start;            /* where intuit found a patch */
  88.   
  89.   /* Prepare to look for the next patch in the patch file. */
  90.   
  91.  
  92. --- 43,50 -----
  93.   static int p_indent;            /* indent to patch */
  94.   static LINENUM p_base;            /* where to intuit this time */
  95.   static LINENUM p_start;            /* where intuit found a patch */
  96. + static LINENUM p_efake = -1;        /* end of faked up lines--don't free */
  97. + static LINENUM p_bfake = -1;        /* beg of faked up lines */
  98.   
  99.   /* Prepare to look for the next patch in the patch file. */
  100.   
  101. ***************
  102. *** 386,393
  103.       Reg2 int context = 0;
  104.   
  105.       while (p_end >= 0) {
  106. !     free(p_line[p_end]);        /* Changed from postdecrement */
  107. !     p_end--;            /* by Keenan Ross for BSD2.9  */
  108.       }
  109.       assert(p_end == -1);
  110.   
  111.  
  112. --- 391,401 -----
  113.       Reg2 int context = 0;
  114.   
  115.       while (p_end >= 0) {
  116. !     if (p_end == p_efake)
  117. !         p_end = p_bfake;        /* don't free twice */
  118. !     else
  119. !         free(p_line[p_end]);
  120. !     p_end--;
  121.       }
  122.       assert(p_end == -1);
  123.       p_efake = -1;
  124. ***************
  125. *** 390,395
  126.       p_end--;            /* by Keenan Ross for BSD2.9  */
  127.       }
  128.       assert(p_end == -1);
  129.   
  130.       p_max = hunkmax;            /* gets reduced when --- found */
  131.       if (diff_type == CONTEXT_DIFF || diff_type == NEW_CONTEXT_DIFF) {
  132.  
  133. --- 398,404 -----
  134.       p_end--;
  135.       }
  136.       assert(p_end == -1);
  137. +     p_efake = -1;
  138.   
  139.       p_max = hunkmax;            /* gets reduced when --- found */
  140.       if (diff_type == CONTEXT_DIFF || diff_type == NEW_CONTEXT_DIFF) {
  141. ***************
  142. *** 637,642
  143.       
  144.       /* if there were omitted context lines, fill them in now */
  145.       if (fillcnt) {
  146.           while (fillcnt-- > 0) {
  147.           while (p_char[fillsrc] != ' ')
  148.               fillsrc++;
  149.  
  150. --- 646,653 -----
  151.       
  152.       /* if there were omitted context lines, fill them in now */
  153.       if (fillcnt) {
  154. +         p_bfake = filldst;        /* remember where not to free() */
  155. +         p_efake = filldst + fillcnt - 1;
  156.           while (fillcnt-- > 0) {
  157.           while (p_char[fillsrc] != ' ')
  158.               fillsrc++;
  159.  
  160.