Path: utzoo!mnetor!uunet!lll-winken!lll-lcc!mordor!sri-spam!rutgers!husc6!bbn!uwmcsd1!ig!agate!ucbvax!GINGER.BERKELEY.EDU!douglis From: douglis@GINGER.BERKELEY.EDU (Fred Douglis) Newsgroups: comp.mail.mh Subject: Re: question about "repl -build" Message-ID: <8802011904.AA08676@sloth.Berkeley.EDU> Date: 1 Feb 88 19:03:59 GMT Sender: daemon@ucbvax.BERKELEY.EDU Lines: 67 Enough people have asked about this that I might as well post this to the newsgroup. (I had hoped that mail to bug-mh would automatically get posted, but apparently not.) ------- Forwarded Message Date: Fri, 29 Jan 88 10:43:36 -0800 From: Fred Douglis To: lemke@sun.com cc: weissman@decwrl.dec.com, bug-mh@uci.edu, larus@ginger.Berkeley.EDU Subject: Bug in formatsbr Terry Weissman responded to my note on comp.mail.mh as follows: Whenever mh needs an mh-format string (for example, to specify the layout of fields in a "scan" or "inc"), it calls the routine new_fs(), which appears in sbr/formatsbr.c. If the format string is stored in a file, this routine mallocs a string exactly the length of the file, and copies the file into that string. There is absolutely nothing done to ensure that the string is null-terminated. new_fs() should malloc a string which is one character longer than the length of the file, and put a null in that last character. The following patch seems to have done the trick. If it's appropriate to post this on the net, and mail to bug-mh isn't already gatewayed, please feel free to repost this. *** /tmp/,RCSt1a11609 Fri Jan 29 10:41:51 1988 - --- formatsbr.c Fri Jan 29 10:27:06 1988 *************** *** 44,50 if (fstat (fileno (fp), &st) == NOTOK) adios (form, "unable to stat format file"); ! if ((formats = malloc ((unsigned) st.st_size)) == NULLCP) adios (form, "unable to allocate space for format"); if (read (fileno(fp), formats, st.st_size) != st.st_size) - --- 44,50 ----- if (fstat (fileno (fp), &st) == NOTOK) adios (form, "unable to stat format file"); ! if ((formats = malloc ((unsigned) st.st_size + 1)) == NULLCP) adios (form, "unable to allocate space for format"); if (read (fileno(fp), formats, st.st_size) != st.st_size) *************** *** 49,54 if (read (fileno(fp), formats, st.st_size) != st.st_size) adios (form, "error reading format file"); (void) fclose (fp); } - --- 49,56 ----- if (read (fileno(fp), formats, st.st_size) != st.st_size) adios (form, "error reading format file"); + + formats[st.st_size] = '\0'; (void) fclose (fp); } ------- End of Forwarded Message