From nobody@FreeBSD.org  Wed Aug 10 15:08:06 2005
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id E42FF16A41F
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 10 Aug 2005 15:08:06 +0000 (GMT)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [216.136.204.117])
	by mx1.FreeBSD.org (Postfix) with ESMTP id B641543D48
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 10 Aug 2005 15:08:06 +0000 (GMT)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.13.1/8.13.1) with ESMTP id j7AF86Nl039908
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 10 Aug 2005 15:08:06 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.13.1/8.13.1/Submit) id j7AF86od039907;
	Wed, 10 Aug 2005 15:08:06 GMT
	(envelope-from nobody)
Message-Id: <200508101508.j7AF86od039907@www.freebsd.org>
Date: Wed, 10 Aug 2005 15:08:06 GMT
From: James Juran <James.Juran@baesystems.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: shutdown() of non-connected socket should fail with ENOTCONN
X-Send-Pr-Version: www-2.3

>Number:         84761
>Category:       kern
>Synopsis:       shutdown() of non-connected socket should fail with ENOTCONN
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bms
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Aug 10 15:10:17 GMT 2005
>Closed-Date:    Sun Mar 18 02:04:13 GMT 2007
>Last-Modified:  Sun Mar 18 02:04:13 GMT 2007
>Originator:     James Juran
>Release:        5.3-RELEASE
>Organization:
BAE Systems Inc.
>Environment:
FreeBSD bsdv6 5.3-RELEASE FreeBSD 5.3-RELEASE #0: Fri Nov  5 04:19:18 UTC 2004
root@harlow.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC  i386
>Description:
Calling shutdown(2) on a non-connected socket should fail with ENOTCONN
according to the manpage.  Instead, it succeeds.

>How-To-Repeat:
Run this program.  It should hit the perror(), but instead prints
"shutdown succeeded".

#include <stdio.h>
#include <stdlib.h>
#include <sys/socket.h>

int main(void)
{
    int s;

    s = socket(PF_INET, SOCK_STREAM, 0);
    if (s == -1)
    {
        perror("socket");
        exit(1);
    }

    if (shutdown(s, SHUT_RD) == -1)
        perror("shutdown");
    else
        printf("shutdown succeeded\n");

    return 0;
}

>Fix:
Check for SS_ISCONNECTED in soshutdown, and return ENOTCONN if it
is not set.

>Release-Note:
>Audit-Trail:

From: Maxim Konovalov <maxim@macomnet.ru>
To: James Juran <James.Juran@baesystems.com>
Cc: bug-followup@freebsd.org, rwarson@freebsd.org
Subject: Re: kern/84761: shutdown() of non-connected socket should fail with
 ENOTCONN
Date: Wed, 10 Aug 2005 21:57:44 +0400 (MSD)

 Hi,
 
 [...]
 > Calling shutdown(2) on a non-connected socket should fail with ENOTCONN
 > according to the manpage.  Instead, it succeeds.
 
 Indeed, Linux 2.4 and Solaris 9 return ENOTCONN.  It seems all BSDs
 don't.
 
 > >How-To-Repeat:
 > Run this program.  It should hit the perror(), but instead prints
 > "shutdown succeeded".
 
 Here is a patch but I'm not sure about it and CC'ed rwatson@.  Robert,
 what do you think?
 
 Index: uipc_socket.c
 ===================================================================
 RCS file: /home/ncvs/src/sys/kern/uipc_socket.c,v
 retrieving revision 1.242
 diff -u -p -r1.242 uipc_socket.c
 --- uipc_socket.c	1 Jul 2005 16:28:30 -0000	1.242
 +++ uipc_socket.c	10 Aug 2005 17:20:39 -0000
 @@ -1428,7 +1428,8 @@ soshutdown(so, how)
 
  	if (!(how == SHUT_RD || how == SHUT_WR || how == SHUT_RDWR))
  		return (EINVAL);
 -
 +	if ((so->so_state & SS_ISCONNECTED) == 0)
 +		return (ENOTCONN);
  	if (how != SHUT_WR)
  		sorflush(so);
  	if (how != SHUT_RD)
 %%%
 
 -- 
 Maxim Konovalov

From: Maxim Konovalov <maxim@macomnet.ru>
To: James Juran <James.Juran@baesystems.com>
Cc: bug-followup@freebsd.org, rwatson@freebsd.org
Subject: Re: kern/84761: shutdown() of non-connected socket should fail with
 ENOTCONN
Date: Wed, 10 Aug 2005 23:15:31 +0400 (MSD)

 shutdown(2) regression test based on Robert's listenclose test:
 
 	http://maxim.int.ru/stuff/shutdown/
 
 -- 
 Maxim Konovalov
State-Changed-From-To: open->patched 
State-Changed-By: maxim 
State-Changed-When: Thu Sep 15 11:45:58 GMT 2005 
State-Changed-Why:  
Fixed in HEAD, thanks! 


Responsible-Changed-From-To: freebsd-bugs->maxim 
Responsible-Changed-By: maxim 
Responsible-Changed-When: Thu Sep 15 11:45:58 GMT 2005 
Responsible-Changed-Why:  
MFC in 1 month. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=84761 
State-Changed-From-To: patched->open 
State-Changed-By: maxim 
State-Changed-When: Thu Sep 15 13:20:50 GMT 2005 
State-Changed-Why:  
The code was backouted. 


Responsible-Changed-From-To: maxim->freebsd-bugs 
Responsible-Changed-By: maxim 
Responsible-Changed-When: Thu Sep 15 13:20:50 GMT 2005 
Responsible-Changed-Why:  
Return to the pool and let more knowledgeable people to deal with 
the issue.  See 

http://lists.freebsd.org/pipermail/cvs-src/2005-September/052383.html 

for more information. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=84761 
State-Changed-From-To: open->patched 
State-Changed-By: bms 
State-Changed-When: Mon Mar 5 12:40:02 UTC 2007 
State-Changed-Why:  
dealt with in man pages 

http://www.freebsd.org/cgi/query-pr.cgi?pr=84761 
Responsible-Changed-From-To: freebsd-bugs->bms 
Responsible-Changed-By: bms 
Responsible-Changed-When: Mon Mar 5 12:40:16 UTC 2007 
Responsible-Changed-Why:  
dealing with this 

http://www.freebsd.org/cgi/query-pr.cgi?pr=84761 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/84761: commit references a PR
Date: Mon,  5 Mar 2007 12:40:01 +0000 (UTC)

 bms         2007-03-05 12:39:53 UTC
 
   FreeBSD src repository
 
   Modified files:
     lib/libc/sys         shutdown.2 
   Log:
   Update shutdown() manual page to reflect actual behaviour of code.
   
   Add IMPLEMENTATION NOTES section explaining in detail the effect this
   system call has in common use cases involving PF_INET and PF_INET6 sockets.
   
   PR:             kern/84761
   MFC after:      2 days
   
   Revision  Changes    Path
   1.17      +82 -10    src/lib/libc/sys/shutdown.2
 _______________________________________________
 cvs-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/cvs-all
 To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: patched->closed 
State-Changed-By: bms 
State-Changed-When: Sun Mar 18 02:04:04 UTC 2007 
State-Changed-Why:  
was mfc'd 

http://www.freebsd.org/cgi/query-pr.cgi?pr=84761 
>Unformatted:
