[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: gawk 3.1.6 bug in /inet/tcp/lport/0/0
From: |
Aharon Robbins |
Subject: |
Re: gawk 3.1.6 bug in /inet/tcp/lport/0/0 |
Date: |
Fri, 30 Nov 2007 11:16:58 +0200 |
Richard and Corinna:
> Date: Thu, 15 Nov 2007 22:45:01 +0100
> From: Corinna Vinschen <address@hidden>
> Subject: Re: gawk 3.1.6 bug in /inet/tcp/lport/0/0
> To: Aharon Robbins <address@hidden>
> Cc: address@hidden, address@hidden
>
> On Nov 15 23:07, Aharon Robbins wrote:
> > Greetings. Re the below. I don't get any such message under Linux.
> > Please talk to the cygwin people directly. I have bcc'ed the Cygwin
> > contact for gawk, so I hope she will be in touch w/you directly.
> >
> > Thanks,
> >
> > Arnold
> >
> > > From: Richard Narum
> > > FYI,
> > >
> > > I believe I have encountered a bug in gawk 3.1.6 with the special file
> > > name /inet/tcp using lport != 0 and rhost = rport = 0. I am running
> > > Cygwin on Windows XP version "CYGWIN_NT-5.1 1.5.24(0.156/4/2) 2007-01-31
> > > 10:57". I had version "GNU Awk 3.1.6", Cygwin install calls it 3.1.6-1,
> > > and had to roll back to "GNU Awk 3.1.5", Cygwin's 3.1.5-4 . Version
> > > 3.1.6 fails and 3.1.5 seems to work fine.
> > >
> > > I am running the following script.
> > >
> > >
> > > #!/bin/sh
> > >
> > > gawk '
> > > BEGIN {
> > > RS = ORS = "\r\n"
> > > HttpService = "/inet/tcp/8080/0/0"
> > > Hello = "<HTML><HEAD></HEAD><BODY><PRE>Hello World!</PRE></BODY></HTML>"
> > > Len = length(Hello) + length(ORS)
> > > while ("awk" != "complex") {
> > > print "HTTP/1.0 200 OK" |& HttpService
> > > print "Content-Length: " Len ORS |& HttpService
> > > print Hello |& HttpService
> > > while ((HttpService |& getline) > 0)
> > > continue;
> > > close(HttpService)
> > > }
> > > }
> > > '
> > >
> > > I get the following error.
> > >
> > >
> > > gawk: cmd. line:8: fatal: remote host and port information (0, 0) invalid
>
> That's a regression in io.c, function socketopen. The 3.1.5 code
> called gethostbyname on a hostname "0", which leads to gethostbyname
> returning NULL. However, this wasn't a problem because the code
> explicitely checked for an input remote address of "0" and, if so,
> allowed gethostbyname to fail without socketopen to fail:
>
> io.c:
>
> 1137 struct hostent *hp = gethostbyname(remotehostname);
> [...]
> 1140 int any_remote_host = strcmp(remotehostname, "0");
> [...]
> 1180 if (socket_fd < 0 || socket_fd == INVALID_HANDLE
> * 1181 || (hp == NULL && any_remote_host != 0))
> 1182 return INVALID_HANDLE;
>
> In 3.1.6, the function getaddrinfo is used. If getaddrinfo returns -1,
> gawk fails to open the socket, because there's no further test for
> any_remote_host. I don't know why this works on Linux, but it certainly
> fails on Cygwin, because Cygwin doesn't have (so far) a getaddrinfo
> function and so the fallback function in missing_d is used, which in turn
> uses gethostbyname. Since gethostbyname fails with the remote hostname
> "0", the whole socketopen function fails now. I'm sure this isn't a
> problem only on Cygwin, though, but on any platform not having its own
> getaddrinfo function.
>
> Since the socketopen function has changed so enormously, I don't see an
> easy patch for this.
>
> Corinna
I looked into this. The use of `any_remote_host' changed from 3.1.5 to 3.1.6.
In 3.1.6 it is a correctly-used boolean and the logic that's there is fine.
Under Linux, even when using the replacement getaddrinfo that calls
gethostbyname,
a hostname argument of "0" still seems to "work", in that gethostbyname does NOT
return NULL. This is a bit weird. In any case I think that the patch below
will fix things for cygwin (and other systems).
Please try it out and let me know.
Thanks!
Arnold
-------------------------------------------------
Fri Nov 30 11:11:52 2007 Arnold D. Robbins <address@hidden>
* io.c (socketopen): Use NULL as first argument to `getaddrinfo'
if any_remote_host is true. Should help on Non-GLIBC systems.
===================================================================
--- io.c 11 Aug 2007 19:49:23 -0000 1.13
+++ io.c 30 Nov 2007 09:11:22 -0000
@@ -1208,7 +1208,7 @@
rhints.ai_family = lhints.ai_family;
rhints.ai_protocol = lhints.ai_protocol;
- rerror = getaddrinfo (remotehostname, remotepname, &rhints,
&rres);
+ rerror = getaddrinfo (any_remote_host ? NULL : remotehostname,
remotepname, &rhints, &rres);
if (rerror) {
if (lres0 != NULL)
freeaddrinfo(lres0);
- Re: gawk 3.1.6 bug in /inet/tcp/lport/0/0,
Aharon Robbins <=