Thu Feb 7 05:58:00 GMT 2002
On Wed, Feb 06, 2002 at 01:07:28PM -0500, Jason Tishler wrote:
> The attached patch fixes a SEGV when getsockname () is called. This
> problem can be tickled by the PostgreSQL 7.2 version of psql:
> Note that I essentially plagiarized the following commit:
> Was this the right thing to do?
The patch isn't correct since it now calls fdsock() twice which allocates
a new fhandler even if the line before already had created one.
fhandler_socket* res_fh = fdsock (fd, name, soc)->set_addr_family (af);
if (af == AF_LOCAL)
However, I don't understand the need for that patch. Does postgresql
call getsockname() before calling bind()? I didn't know that that makes
sense. Sure, it shouldn't SEGV but the returned name doesn't make
sense on non-Cygwin systems either.
A quick test on Linux returns:
[~]$ ./uds /tmp/mysocket
Before bind(): name = ÿ¿M`@(R`@b, returned len = 2
After bind() : name = /tmp/mysocket, returned len = 16
So, IMO, the correct way is to clean up cygwin_getsockname()
so that it always returns "something" instead of SEGVing.
Could you please test the below patch if that works with postgresql?
* net.cc (cygwin_getsockname): Fix handling of NULL sun_path.
RCS file: /cvs/src/src/winsup/cygwin/net.cc,v
retrieving revision 1.99
diff -u -p -r1.99 net.cc
--- net.cc 2002/01/29 13:39:41 1.99
+++ net.cc 2002/02/07 13:53:11
@@ -1375,12 +1375,17 @@ cygwin_getsockname (int fd, struct socka
struct sockaddr_un *sun = (struct sockaddr_un *) addr;
memset (sun, 0, *namelen);
sun->sun_family = AF_LOCAL;
- /* According to SUSv2 "If the actual length of the address is greater
- than the length of the supplied sockaddr structure, the stored
- address will be truncated." We play it save here so that the
- path always has a trailing 0 even if it's truncated. */
- strncpy (sun->sun_path, sock->get_sun_path (),
- *namelen - sizeof *sun + sizeof sun->sun_path - 1);
+ if (!sock->get_sun_path ())
+ sun->sun_path = '\0';
+ /* According to SUSv2 "If the actual length of the address is
+ greater than the length of the supplied sockaddr structure, the
+ stored address will be truncated." We play it save here so
+ that the path always has a trailing 0 even if it's truncated. */
+ strncpy (sun->sun_path, sock->get_sun_path (),
+ *namelen - sizeof *sun + sizeof sun->sun_path - 1);
*namelen = sizeof *sun - sizeof sun->sun_path
+ strlen (sun->sun_path) + 1;
res = 0;
Corinna Vinschen Please, send mails regarding Cygwin to
Cygwin Developer mailto:email@example.com
Red Hat, Inc.
More information about the Cygwin-patches