delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2000/06/26/09:36:40

Mailing-List: contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT sourceware DOT cygnus DOT com>
List-Archive: <http://sourceware.cygnus.com/ml/cygwin/>
List-Post: <mailto:cygwin AT sourceware DOT cygnus DOT com>
List-Help: <mailto:cygwin-help AT sourceware DOT cygnus DOT com>, <http://sourceware.cygnus.com/ml/#faqs>
Sender: cygwin-owner AT sourceware DOT cygnus DOT com
Delivered-To: mailing list cygwin AT sourceware DOT cygnus DOT com
X-Mail-Server: Eserv/2.92/ÈÒÖ "ÎÐÃÒÅÕÄÈÀÃÍÎÑÒÈÊÀ"
Message-ID: <39575D69.A83E2E12@kbotd.ru>
Date: Mon, 26 Jun 2000 17:40:58 +0400
From: Alexander Trush <trush AT kbotd DOT ru>
X-Mailer: Mozilla 4.61 [en] (WinNT; I)
X-Accept-Language: ru,en
MIME-Version: 1.0
To: cygwin AT sourceware DOT cygnus DOT com
Subject: cygwin1.dll (v1.1.2): dup2() with invalid newfd lead to exception:
STATUS_ACCESS_VIOLATION

--------------D5C19BBFB793B9C5A51F459D
Content-Type: text/plain; charset=koi8-r
Content-Transfer-Encoding: 7bit

Hi!

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.

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


--------------D5C19BBFB793B9C5A51F459D
Content-Type: text/html; charset=koi8-r
Content-Transfer-Encoding: 7bit

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

--------------D5C19BBFB793B9C5A51F459D--

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019