This is the mail archive of the cygwin@sourceware.cygnus.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: cygwin1.dll (v1.1.2): dup2() with invalid newfd lead to exception: STATUS_ACCESS_VIOLATION


On Mon, Jun 26, 2000 at 05:40:58PM +0400, Alexander Trush wrote:
>I have loaded the last version of the environment CygWin and attempted
>to compile SQUID-2.3.STABLE3. In the configurator SQUID there is a piece
>of the code: " checking Maximum number of filedescriptors we can open ",
>this code utillize the function dup2(), which one with invalid value of
>argument reduces to in crash of the program instead of returning an
>error code.

It was a problem with an out of bounds "new fd".  I've checked in a patch
to fix this.  It will be in the next snapshot and also in the next net release.

Thanks for the bug report and, most importantly for a relatively simple test
case so that we didn't have to guess about what was wrong.

cgf

>Piece of this code:
>
>#include "confdefs.h"
>
>#include <stdio.h>
>#include <unistd.h>
>#include <sys/time.h>   /* needed on FreeBSD */
>#include <sys/param.h>
>#include <sys/resource.h>
>main() {
>        FILE *fp;
>        int i,j;
>#if __CYGWIN32__
>    /* getrlimit and sysconf returns bogous values on cygwin32.
>     * Number of fds is virtually unlimited in cygwin (sys/param.h)
>     */
>    i = NOFILE;
>#elif HAVE_SETRLIMIT
>    struct rlimit rl;
>#if defined(RLIMIT_NOFILE)
>    if (getrlimit(RLIMIT_NOFILE, &rl) < 0) {
>        perror("getrlimit: RLIMIT_NOFILE");
>    } else {
>        rl.rlim_cur = rl.rlim_max;      /* set it to the max */
>        if (setrlimit(RLIMIT_NOFILE, &rl) < 0) {
>            perror("setrlimit: RLIMIT_NOFILE");
>        }
>    }
>#elif defined(RLIMIT_OFILE)
>    if (getrlimit(RLIMIT_OFILE, &rl) < 0) {
>        perror("getrlimit: RLIMIT_OFILE");
>    } else {
>        rl.rlim_cur = rl.rlim_max;      /* set it to the max */
>        if (setrlimit(RLIMIT_OFILE, &rl) < 0) {
>            perror("setrlimit: RLIMIT_OFILE");
>        }
>    }
>#endif /* RLIMIT_NOFILE */
>#endif /* HAVE_SETRLIMIT */
>        /* by starting at 2^14, we will never get higher
>        than 2^15 for SQUID_MAXFD */
>        i = j = 1<<14;
>        while (j) {
>                j >>= 1;
>                if (dup2(0, i) < 0) {
>                        i -= j;
>                } else {
>                        close(i);
>                        i += j;
>                }
>        }
>        i++;
>        fp = fopen("conftestval", "w");
>        fprintf (fp, "%d\n", i);
>        exit(0);
>}
>
>
>
>
>The elementary test routine resulting in to the same result (under
>Borland 5.02 all is correct - " Ret val =-1, errno=0 "):
>
>
>test.c:
>-------
>#include <stdio.h>
>#include <io.h>
>#include <errno.h>
>
>void main(void)
>{
>        printf("Ret val=%d, errno=%d", dup2(0, 1<<14), errno);
>}
>
>
>
>bash-2.04$ cd /usr/src/squid-2.3.STABLE3
>bash-2.04$ gcc test.c -o test.exe
>test.c: In function `main':
>test.c:6: warning: return type of `main' is not `int'
>bash-2.04$ ./test.exe
>      0 [main] test 1008 handle_exceptions: Exception:
>STATUS_ACCESS_VIOLATION
>   1392 [main] test 1008 stackdump: Dumping stack trace to
>test.exe.stackdump
>bash-2.04$
>
>
>test.exe.stackdump:
>-------------------
>Exception: STATUS_ACCESS_VIOLATION at eip=6101F19A
>eax=0A040E08 ebx=FFFFFFFF ecx=7FFDE000 edx=61084BE8 esi=00004000
>edi=0A0416B8
>ebp=0246FE5C esp=0246FE40
>program=c:\CygWIN\usr\src\squid-2.3.STABLE3\test.exe
>cs=001B ds=0023 es=0023 fs=003B gs=0000 ss=0023
>Stack trace:
>Frame     Function  Args
>0246FE5C  6102F23B  (61084BE8, 00000000, 00004000, 0247273B)
>0246FE7C  6102F23B  (00000000, 00004000, 0246FEC8, 0246FEA4)
>0246FEA4  0040107F  (00000001, 0A041688, 0A040008, 00000000)
>0246FF00  61002385  (7FFDF000, 00000000, 0247DF10, 77F9D0E8)
>0246FF60  610027D5  (00403010, C0059000, 0246FF90, 004011BA)
>0246FF90  004011C7  (00401058, 815C04C0, 00000246, 801174E1)
>0246FFC0  0040103B  (0247DF10, 00000000, 7FFDF000, 7FFDF000)
>0246FFF0  77F1B9EA  (00401000, 00000000, 000000B0, 00000100)
>End of stack trace
>

-- 
cgf@cygnus.com                        Cygnus Solutions, a Red Hat company
http://sourceware.cygnus.com/         http://www.redhat.com/

--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe@sourceware.cygnus.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]