[news.software.b] unguarded calls to fgets

shields@yunccn (Paul Shields) (03/16/88)

I have had some problems trying to get news patch level 8 up on SCO Xenix.
Vnews mysteriously dumps core now and again. (No, I can't use rn instead.)
I can't help thinking that this might be behind the problems people have been
experiencing at patch level 14.

I traced this to articles that were cross-posted to more than about 5 groups,
suspected that SMALL_ADDRESS_SPACE had something to do with it, (yes, I _must_
define that) and then noticed that in several places all through news (vnews, 
readnews, expire, inews)  there appear unguarded calls to fgets(). 

Since fgets() is not guaranteed to write a '\0' after it reads, you can
end up with memory garbage tacked onto your strings. Who knows what could 
happen?  Anyways, it's trivial to fix. Anywhere it appears, use this
sort of thing instead: 

	char buf[BUFLEN+1];
	...
	buf[BUFLEN] = '\0';
	rc = fgets(buf, BUFLEN, fp);
	....

This corrects the problem at patch level 8. (PLEASE don't ask me for diffs)
I thought I'd report on it before I upgraded to the latest version.
-- 
Paul Shields, shields@yunccn.UUCP

Communication is a two-way street.  Don't get run over.