Subject: lib/6322: fclose(NULL) segfaults
To: None <>
From: None <>
List: netbsd-bugs
Date: 10/17/1998 19:28:47
>Number:         6322
>Category:       lib
>Synopsis:       fclose(NULL) segfaults
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    lib-bug-people (Library Bug People)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Oct 17 16:35:00 1998
>Originator:     Darrin B. Jewell
>Release:        1.3.2 as well as -current updated around 19981011.1745

System: NetBSD pan-fried-peking-ravioli 1.3H NetBSD 1.3H (PAN-FRIED-PEKING-RAVIOLI) #3: Sun Oct 11 21:20:20 EDT 1998 jewell@pan-fried-peking-ravioli:/u2/PAN-FRIED-PEKING-RAVIOLI i386


fclose(NULL) produces a segmentation fault error.

Perhaps it should return EOF and set errno to EBADF.

Then again perhaps the users deserve what they get for handing
random junk to libc functions.


Compile and run the following program:

#include <stddef.h>
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>

main(int argc, char *argv[])
  int ret;
  ret = fclose(NULL);
  assert(ret == EOF);