fclose() again

From: Evan Langlois (goth_74@yahoo.com)
Date: Fri Jul 14 2000 - 18:17:04 EDT

  • Next message: Henrik Størner: "Something odd with 2.4.0-test4 - pipes or suid/sgid broken ?"

    Well, originally, I thought you had a point, but I'm willing to admit.
    I was WRONG.

    #So FILE *stdin is like any other FILE *. It should work by the same
    #rules.

    It does

    #The BUG, and it is a BUG, is that a seldom used function like fclose()
    #has been 'optimized'.

    Yup, it has. The library does not check to make sure the programmer knows
    whats he is doing, it just does as its told.

    #struct _IO_FILE contains some pointers. If these pointers are dereferenced
    #during the fclose(), and they are NULL, or point to memory you don't own,
    #your program will seg-fault.

    Correct! the library shouldn't have to check the pointers cause if you use
    the calls properly, it won't sefault.

    #fclose() should check these structure members and return EBADF,
    #as specified, instead of just crashing.

    Actually, it specifies that:
            "In either case any further access
           (including another call to fclose()) to the stream results
           in undefined behaviour."

    "undefined behavior" is your segfault, however, it could do anything, its a
    hanging pointer.

    #Now, if the specification of fclose() allowed a seg-fault that's quite
    #another thing. According to Linux's own documentation, it should
    #return with -1 and set errno to EBADF if I give it trash.

    This is not only NOT a linux kernel issue, its not even a linux issue at all.
    I believe the C library is GNU, and I think its correct behavior since, as
    someone already pointed out to me (thanks!), it DOES say it will give
    undefined behavior if you access a closed stream - and by extension, this can
    also refer to something that isn't a stream at all. Don't fclose() something
    thats already closed. Manage your code better, or use perl :)

    And uhmm .. do you REALLY read your mail as root? Lets not bug the list no
    more with this, k?

    --Evan

    __________________________________________________
    Do You Yahoo!?
    Get Yahoo! Mail – Free email you can access from anywhere!
    http://mail.yahoo.com/

    -
    To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
    the body of a message to majordomo@vger.rutgers.edu
    Please read the FAQ at http://www.tux.org/lkml/



    This archive was generated by hypermail 2b29 : Fri Jul 14 2000 - 18:21:09 EDT