bruce@stride.UUCP (Bruce Robertson) (03/26/86)
Description: There is a bug in the doprnt() function for System V, Release 2, Version 2. doprnt() does its own interfacing to the stdio data structures, rather than using fwrite() and/or putc(). When writing to a FILE stream, it is the responsibility of whoever is going to manipulate the data structures to use the _WRTCHK macro to insure that an I/O buffer is allocated on the stream. doprnt() fails to do this. Repeat-By: Occasionally, redirecting output of a program that does nothing but printf()'s to a file will cause the program to core dump. Fix: *** /usr/src/lib/libc/port/print/doprnt.c-old Tue Mar 25 21:26:22 1986 --- /usr/src/lib/libc/port/print/doprnt.c Tue Mar 25 21:26:25 1986 *************** *** 9,14 #include <varargs.h> #include <values.h> #include "print.h" /* parameters & macros for doprnt */ #define PUT(p, n) { register unsigned char *newbufptr; \ if ((newbufptr = bufptr + n) > bufferend) { \ --- 9,15 ----- #include <varargs.h> #include <values.h> #include "print.h" /* parameters & macros for doprnt */ + #include "../stdio/stdiom.h" #define PUT(p, n) { register unsigned char *newbufptr; \ if ((newbufptr = bufptr + n) > bufferend) { \ *************** *** 153,158 /* initialize buffer pointer and buffer end pointer */ { register int fno = iop->_file; bufptr = iop->_ptr; bufferend = (fno == _NFILE) ? (unsigned char *)((long) bufptr | (-1L & ~HIBITL)) --- 154,161 ----- /* initialize buffer pointer and buffer end pointer */ { register int fno = iop->_file; + if (_WRTCHK(iop)) + return EOF; bufptr = iop->_ptr; bufferend = (fno == _NFILE) ? (unsigned char *)((long) bufptr | (-1L & ~HIBITL)) -- Bruce Robertson UUCP: cbosgd!utah-cs!utah-gr!stride!bruce ARPA: stride!bruce@utah-gr.arpa