[net.bugs] bug in stdio

crl@CSvax:Pucc-H:pur-phy.UUCP (09/09/83)

I think I have discovered a bug in the way stdio handles its buffers
when you've used setbuf().  We run 2.8 BSD, but I bet it's present
elsewhere.  It seems that iop->_base is not set to NULL by fclose
if you've used a setbuf() to assign your own buffer.  The specific
code is:
	if (iop->_flag & _IOMYBUF)
		free(iop->_base);
	if (iop->_flag & (_IOMYBUF|_IONBF))
		iop->_base = NULL;
in fclose().  Thus, if _base was pointing to your stack, you'll in for
problems the next time you fopen() since this does not zero it either.
I can't think of a good reason why _base should not be zeroed on an
fclose().  Comments?

Charles LaBrec
UUCP:		pur-ee!Physics:crl, purdue!Physics:crl
INTERNET:	crl @ pur-phy.UUCP

guy@rlgvax.UUCP (Guy Harris) (09/12/83)

This bug also causes problems if the buffer is static (it gets reused
improperly).  See my article 1127@rlgvax.UUCP.  Article 30@ism780.UUCP
stated that the simple fix won't fix it, and that it has been fixed in
System V.

	Guy Harris
	{seismo,mcnc,we13,brl-bmd,allegra}!rlgvax!guy