From jkf@sys1.microline.org  Fri Apr 17 08:05:47 1998
Received: from sys1.microline.org (jkf@microline.org [207.173.132.199])
          by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id IAA02344
          for <FreeBSD-gnats-submit@freebsd.org>; Fri, 17 Apr 1998 08:05:45 GMT
          (envelope-from jkf@sys1.microline.org)
Received: (from jkf@localhost)
	by sys1.microline.org (8.8.8/8.8.7) id BAA22860;
	Fri, 17 Apr 1998 01:05:25 -0700 (PDT)
	(envelope-from jkf)
Message-Id: <199804170805.BAA22860@sys1.microline.org>
Date: Fri, 17 Apr 1998 01:05:25 -0700 (PDT)
From: "Jason K. Fritcher" <jkf@microline.org>
Reply-To: fritcher@calweb.com
To: FreeBSD-gnats-submit@freebsd.org
Subject: _thread_flockfile hangs with NULL file pointer.
X-Send-Pr-Version: 3.2

>Number:         6329
>Category:       misc
>Synopsis:       _thread_flockfile hangs with NULL file pointer.
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Apr 17 01:10:14 PDT 1998
>Closed-Date:    Sun Apr 26 00:02:06 PDT 1998
>Last-Modified:  Sun Apr 26 00:02:35 PDT 1998
>Originator:     Jason K. Fritcher
>Release:        FreeBSD 2.2.6-STABLE i386
>Organization:
N/A
>Environment:

FreeBSD sys1.microline.org 2.2.6-STABLE FreeBSD 2.2.6-STABLE #0: Sun Apr  5
14:20:20 PDT 1998  root@sys1.microline.org:/usr/src/sys/compile/microline i386

>Description:

Calling any function that calls _thread_flockfile with a file pointer that
happens to be NULL, the function will hang, and consume call idle cpu time.

>How-To-Repeat:

Save this to a file, ie blah.c.

#include <pthread.h>
#include <stdio.h>

main()
{
        FILE*   fBlah = NULL;

        fprintf(fBlah, "Blah\n");
}


Then do this:

  gcc -lc_r -o blah blah.c
  ./blah

hangs. Have to 'kill -9' to stop.


But this:

  gcc -o blah blah.c
  ./blah

core dumps as expected.


>Fix:

Apply this patch to /usr/src/lib/libc_r/uthread/uthread_file.c

--- uthread_file.c.old  Sun Jan 21 16:23:18 1996
+++ uthread_file.c      Thu Apr 16 23:51:22 1998
@@ -42,10 +42,12 @@
        int             fd, flags;
        int             status;

-       /* Block signals: */
-       _thread_kern_sig_block(&status);

        if ((fd = fileno(fp)) >= 0) {
+               /* Block signals: */
+               _thread_kern_sig_block(&status);
+
+
                if (fp->_flags & __SRW) {
                        flags = FD_READ | FD_WRITE;
                } else {
@@ -58,9 +60,10 @@

                /* This might fail but POSIX doesn't give a damn. */
                _thread_fd_lock(fd, flags, NULL, fname, lineno);
+
+               /* Unblock signals: */
+               _thread_kern_sig_unblock(status);
        }
-       /* Unblock signals: */
-       _thread_kern_sig_unblock(status);
        return;
 }
>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed 
State-Changed-By: phk 
State-Changed-When: Sun Apr 26 00:02:06 PDT 1998 
State-Changed-Why:  
the patch doesn't apply to -current, and I think the right 
fix would be a merge from -current. 
>Unformatted:
