[Date Prev][Date Next] [Chronological] [Thread] [Top]

Re: Shell Fork Runaway Bug (ITS#1973)



This is a multi-part message in MIME format.

------=_NextPart_000_001B_01C2316A.F2DC6660
Content-Type: text/plain;
	charset="Windows-1252"
Content-Transfer-Encoding: 7bit

hi,

I found the original patched servers/slapd/back-shell/fork.c
that I have. The unpatched version has not changed at all since 
2.0.25


Here is a diff from the unmodified version.
and the mod fork.c is attached.

7a8,10
>
>
>
15a19,22
> #include <ac/wait.h>
> #include <ac/signal.h>
> #include <ac/errno.h>
>
18a26,52
>
>
> static RETSIGTYPE
> wait4child( int sig )
> {
>   int save_errno = errno;
>
> #ifdef WNOHANG
>   errno = 0;
> #ifdef HAVE_WAITPID
>   while ( waitpid( (pid_t)-1, NULL, WNOHANG ) > 0 || errno == EINTR )
>     ;       /* NULL */
> #else
>   while ( wait3( NULL, WNOHANG, NULL ) > 0 || errno == EINTR )
>     ;       /* NULL */
> #endif
> #else
>   (void) wait( NULL );
> #endif
>   (void) SIGNAL_REINSTALL( sig, wait4child );
>   errno = save_errno;
> }
>
>
>
>
>
84a119,121
>       while ( waitpid( (pid_t)-1, NULL, WNOHANG ) > 0 || errno == EINTR )
>         ;       /* NULL */
>
86a124,129
>
>
>
>
>
>




----- Original Message ----- 
From: <openldap-its@OpenLDAP.org>
To: <anthm@cylynx.com>
Sent: Saturday, July 20, 2002 6:47 PM
Subject: Re: Shell Fork Runaway Bug (ITS#1973)



*** THIS IS AN AUTOMATICALLY GENERATED REPLY ***

Thanks for your report to openldap-its@OpenLDAP.org.  Your report
has been placed into our Issue Tracking System and has been assigned
the tracking number ITS#1973.

One of our support engineers will look at your report in due course.
Note that this may take some time because our support engineers
are volunteers.  They only work on OpenLDAP when they have spare
time.

If you need to provide additional information in regards to your
issue report, you may do so by replying to this message.  Note that
any mail sent to openldap-its@openldap.org with (ITS#1973)
in the subject will automatically be attached to the issue report.

mailto:openldap-its@openldap.org?subject=(ITS#1973)

You may follow the progress of this report by loading the following
URL in a web browser:
    http://www.OpenLDAP.org/its/index.cgi?findid=1973

Please remember to retain your issue tracking number (ITS#1973)
on any further messages you send to us regarding this report.  If
you don't then you'll just waste our time and yours because we
won't be able to properly track the report.

Please note that the Issue Tracking System is not intended to
be used to seek help in the proper use of OpenLDAP Software.
Such requests will be closed.

OpenLDAP Software is user supported.
http://www.OpenLDAP.org/support/

--------------
Copyright 2002 The OpenLDAP Foundation, All Rights Reserved.



------=_NextPart_000_001B_01C2316A.F2DC6660
Content-Type: application/octet-stream;
	name="fork.c"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="fork.c"

/* fork.c - fork and exec a process, connecting stdin/out w/pipes */
/* $OpenLDAP: pkg/ldap/servers/slapd/back-shell/fork.c,v 1.5.8.4 =
2002/01/04 20:38:35 kurt Exp $ */
/*
 * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
 */

#include "portable.h"

#include <stdio.h>

#include <ac/string.h>
#include <ac/socket.h>
#include <ac/unistd.h>

#include "slap.h"
#include "shell.h"

pid_t
forkandexec(
    char        **args,
    FILE        **rfp,
    FILE        **wfp
)
{
        int     p2c[2], c2p[2];
        pid_t   pid;

        if ( pipe( p2c ) !=3D 0 || pipe( c2p ) !=3D 0 ) {
                Debug( LDAP_DEBUG_ANY, "pipe failed\n", 0, 0, 0 );
                return( -1 );
        }

        /*
         * what we're trying to set up looks like this:
         *      parent *wfp -> p2c[1] | p2c[0] -> stdin child
         *      parent *rfp <- c2p[0] | c2p[1] <- stdout child
         */

#ifdef HAVE_THR
        switch ( (pid =3D fork1()) )
#else
        switch ( (pid =3D fork()) )
#endif
        {
        case 0:         /* child */
                /*
                 * child could deadlock here due to resources locked
                 * by our parent
                 *
                 * If so, configure --without-threads or implement =
forking
                 * via a surrogate parent.
                 */
                close( p2c[1] );
                close( c2p[0] );
                if ( dup2( p2c[0], 0 ) =3D=3D -1 || dup2( c2p[1], 1 ) =
=3D=3D -1 ) {
                        Debug( LDAP_DEBUG_ANY, "dup2 failed\n", 0, 0, 0 =
);
                        exit( EXIT_FAILURE );
                }

                execv( args[0], args );

                Debug( LDAP_DEBUG_ANY, "execv failed\n", 0, 0, 0 );
                exit( EXIT_FAILURE );

        case -1:        /* trouble */
                Debug( LDAP_DEBUG_ANY, "fork failed\n", 0, 0, 0 );
                return( -1 );

        default:        /* parent */
                close( p2c[0] );
                close( c2p[1] );
                break;
        }

        if ( (*rfp =3D fdopen( c2p[0], "r" )) =3D=3D NULL || (*wfp =3D =
fdopen( p2c[1],
            "w" )) =3D=3D NULL ) {
                Debug( LDAP_DEBUG_ANY, "fdopen failed\n", 0, 0, 0 );
                close( c2p[0] );
                close( p2c[1] );

                return( -1 );
        }

        return( pid );
}

------=_NextPart_000_001B_01C2316A.F2DC6660--