Subject: patch(1) dumps core on files almost -1 (65535) bytes long (#352) Index: new/patch/inp.c 2.11BSD Description: Patch dumps core when presented with files whose size approaches 64kb. Repeat-By: The manpage for 'csh' is 65392 bytes long. When attempting to update the manpage with the diff included below the 'patch' program dumped core. Fix: Patch attempts to use "plan A" (update the file in memory) first. The patch program tries to malloc enough memory to hold the file and if that fails then "plan B" (use tmp files) is used. The problem is that 'malloc' on a PDP-11 takes the 16 bit number it is passed and rounds it up to the next 'click' (64 byte unit). The size of csh.1 was such that malloc() was calculating a size to allocate of -1 bytes. The fix is to force 'patch' to always use "plan B" if the file is 48kb or larger. To apply the update below cut where indicated, saving to a file (/tmp/352). Then: cd /tmp sh 352 patch -p0 < 352.patch1 cd /usr/src/new/patch make make install make clean cd /tmp patch -p0 < 352.patch2 /usr/man/manroff /usr/src/man/man1/csh.1 > /usr/man/cat1/csh.0 As always these, and all previous updates to 2.11BSD, are available via anonymous FTP to either FTP.IIPO.GTEGSC.COM or MOE.2BSD.COM in the directory /pub/2.11BSD. ========================cut here======================= #! /bin/sh # This is a shell archive, meaning: # 1. Remove everything above the #! /bin/sh line. # 2. Save the resulting text in a file. # 3. Execute the file with /bin/sh (not csh) to create: # 352.patch1 # 352.patch2 # This archive created: Mon Dec 9 22:17:29 1996 export PATH; PATH=/bin:/usr/bin:$PATH if test -f '352.patch1' then echo shar: "will not over-write existing file '352.patch1'" else sed 's/^Z//' << \SHAR_EOF > '352.patch1' Z*** /usr/src/new/patch/inp.c.old Thu Jun 23 12:10:29 1988 Z--- /usr/src/new/patch/inp.c Sat Dec 7 22:22:40 1996 Z*************** Z*** 1,6 **** Z! /* $Header: inp.c,v 2.0.1.1 88/06/03 15:06:13 lwall Locked $ Z * Z * $Log: inp.c,v $ Z * Revision 2.0.1.1 88/06/03 15:06:13 lwall Z * patch10: made a little smarter about sccs files Z * Z--- 1,11 ---- Z! /* $Header: inp.c,v 2.0.1.2 96/12/7 22:15:00 sms $ Z * Z * $Log: inp.c,v $ Z+ * Revision 2.0.1.2 96/12/7 22:15:00 sms Z+ * Files right up against 64kb in size caused patch to core dump because Z+ * a large (negative) value was passed to malloc(). Therefore force Z+ * plan B for files over 48kb in size if on a pdp-11. Z+ * Z * Revision 2.0.1.1 88/06/03 15:06:13 lwall Z * patch10: made a little smarter about sccs files Z * Z*************** Z*** 115,120 **** Z--- 120,133 ---- Z if ((filemode & S_IFMT) & ~S_IFREG) Z fatal2("%s is not a normal file--can't patch.\n", filename); Z i_size = filestat.st_size; Z+ #ifdef pdp11 Z+ /* Z+ * csh.1 was 65392 bytes long and caused patch to core dump because Z+ * malloc() couldn't cope. Z+ */ Z+ if (i_size > 49152L) Z+ return FALSE; Z+ #endif Z if (out_of_mem) { Z set_hunkmax(); /* make sure dynamic arrays are allocated */ Z out_of_mem = FALSE; SHAR_EOF fi if test -f '352.patch2' then echo shar: "will not over-write existing file '352.patch2'" else sed 's/^Z//' << \SHAR_EOF > '352.patch2' Z*** /usr/src/man/man1/csh.1.old Sun Dec 14 15:06:32 1986 Z--- /usr/src/man/man1/csh.1 Wed Nov 27 20:35:56 1996 Z*************** Z*** 2,10 **** Z .\" All rights reserved. The Berkeley software License Agreement Z .\" specifies the terms and conditions for redistribution. Z .\" Z! .\" @(#)csh.1 6.8 (Berkeley) 6/5/86 Z .\" Z! .TH CSH 1 "June 5, 1986" Z .UC 4 Z .de sh Z .br Z--- 2,10 ---- Z .\" All rights reserved. The Berkeley software License Agreement Z .\" specifies the terms and conditions for redistribution. Z .\" Z! .\" @(#)csh.1 6.8.1 (2.11BSD) 1996/11/27 Z .\" Z! .TH CSH 1 "November 27, 1996" Z .UC 4 Z .de sh Z .br Z*************** Z*** 1993,1999 **** Z variable then only full path names will execute. Z The usual search path is `.', `/bin' and `/usr/bin', but this Z may vary from system to system. Z! For the super-user the default search path is `/etc', `/bin' and `/usr/bin'. Z A shell which is given neither the Z .B \-c Z nor the Z--- 1993,2000 ---- Z variable then only full path names will execute. Z The usual search path is `.', `/bin' and `/usr/bin', but this Z may vary from system to system. Z! For the super-user the default search path is `/bin', `/sbin', `/usr/sbin', Z! and `/usr/bin'. Z A shell which is given neither the Z .B \-c Z nor the Z*** /VERSION.old Thu Dec 5 20:01:43 1996 Z--- /VERSION Mon Dec 9 21:59:50 1996 Z*************** Z*** 1,4 **** Z! Current Patch Level: 351 Z Z 2.11 BSD Z ============ Z--- 1,4 ---- Z! Current Patch Level: 352 Z Z 2.11 BSD Z ============ SHAR_EOF fi exit 0 # End of shell archive