Path: utzoo!attcan!uunet!cs.utexas.edu!rutgers!orstcs!jacobs.CS.ORST.EDU!regan From: regan@jacobs.CS.ORST.EDU (Dave Regan) Newsgroups: comp.os.minix Subject: Misfeature in fclose.c Message-ID: <19575@orstcs.CS.ORST.EDU> Date: 30 Jul 90 14:58:53 GMT Sender: usenet@orstcs.CS.ORST.EDU Organization: Oregon State University - CS - Corvallis Lines: 40 It appears that there is a deficiency in fclose when called with a NULL parameter (which isn't good practice anyway). ANSI says that fclose needs to return EOF if the stream was previously closed. The code can be easily extended to protect itself if called with a NULL parameter. If this protection is not in place, at the very least "free" is called with NULL and some other arbitrary value. This isn't good. Note that the loop in fclose WILL find a NULL in the table unless the maximum number of files (NFILES) are open. I have made the change to simply return EOF upon this error. It would be possible to cause an "assert" error and kill the program, as the programmer shouldn't be doing this. regan@jacobs.cs.orst.edu *** /usr/minix-1.5.10/lib/ansi/fclose.c Thu May 17 17:12:55 1990 --- fclose.c Sat Jul 28 21:19:50 1990 *************** *** 13,19 **** _io_table[i] = 0; break; } ! if (i >= NFILES) return(EOF); fflush(fp); close(fp->_fd); if (testflag(fp, IOMYBUF) && fp->_buf) free(fp->_buf); --- 13,19 ---- _io_table[i] = 0; break; } ! if (i >= NFILES || fp == NULL) return(EOF); fflush(fp); close(fp->_fd); if (testflag(fp, IOMYBUF) && fp->_buf) free(fp->_buf);