Path: utzoo!attcan!uunet!lll-winken!lll-tis!ames!fxgrp!ljz From: ljz%fxgrp.fx.com@ames.arc.nasa.gov (Lloyd Zusman) Newsgroups: comp.sources.bugs Subject: Bug fix for APM library. Message-ID: Date: 20 Oct 88 19:22:26 GMT Sender: ljz@fxgrp.UUCP Organization: FX Development Group, Inc., Mountain View, California Lines: 109 Here are the context diffs for a bug fix for the APM library, which was posted to comp.sources.misc a couple weeks ago. When converting APM values to ASCII and right justifying, a segment violation could occur due to a byte copy overflow. Go to the directory where the APM source code is stored, make sure that misc.c is writable, and then type 'patch --- 2,16 ---- * Miscellaneous routines for the APM library. * * $Log: misc.c,v $ + * Revision 1.1 88/10/20 10:45:15 ljz + * Fixed byte copy overflow in apm_convert. + * * Revision 1.0 88/10/05 12:38:14 ljz * Initial release. * */ #ifndef lint ! static char rcsid[] = "$Header: misc.c,v 1.1 88/10/20 10:45:15 ljz Exp $"; #endif /* ! lint */ #include *************** *** 192,197 **** --- 195,201 ---- static int localLen = 0; int roffset; int loffset; + int copylength; int stringlen; int dpos = -1; int n; *************** *** 315,334 **** roffset = 0; loffset = 0; if (length > stringlen) { ! length = stringlen; } } else if (stringlen >= length) { roffset = 0; loffset = stringlen - length; } else { roffset = length - stringlen; loffset = 0; } ! APM_copy_bytes(result + roffset, localString + loffset, length); ! result[length] = '\0'; while (roffset-- > 0) { result[roffset] = ' '; } --- 319,343 ---- roffset = 0; loffset = 0; if (length > stringlen) { ! copylength = stringlen; } + else { + copylength = length; + } } else if (stringlen >= length) { roffset = 0; loffset = stringlen - length; + copylength = length; } else { roffset = length - stringlen; loffset = 0; + copylength = stringlen; } ! APM_copy_bytes(result + roffset, localString + loffset, copylength); ! result[copylength] = '\0'; while (roffset-- > 0) { result[roffset] = ' '; }