NetBSD Problem Report #30921
From soda@netbsd.org Fri Aug 5 17:18:47 2005
Return-Path: <soda@netbsd.org>
Received: from mail.netbsd.org (mail.netbsd.org [204.152.190.11])
by narn.netbsd.org (Postfix) with ESMTP id 6760163B104
for <gnats-bugs@gnats.NetBSD.org>; Fri, 5 Aug 2005 17:18:47 +0000 (UTC)
Message-Id: <20050805171847.56EFE63B162@mail.netbsd.org>
Date: Fri, 5 Aug 2005 17:18:47 +0000 (UTC)
From: SODA Noriyuki <soda@NetBSD.org>
Reply-To: soda@NetBSD.org
To: gnats-bugs@netbsd.org
Cc: SODA Noriyuki <soda@NetBSD.org>
Subject: tsocks doesn't work with tnftp client (patch included)
X-Send-Pr-Version: 3.95
>Number: 30921
>Category: pkg
>Synopsis: tsocks doesn't work with tnftp client (patch included)
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: jmmv
>State: closed
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Fri Aug 05 17:19:00 +0000 2005
>Closed-Date: Sun Sep 17 11:46:01 +0000 2006
>Last-Modified: Sun Sep 17 11:50:01 +0000 2006
>Originator: Noriyuki Soda
>Release: NetBSD 3.0_BETA
>Organization:
the NetBSD project
>Environment:
System: NetBSD srapc2586.sra.co.jp 3.0_BETA NetBSD 3.0_BETA (PC) #0: Fri Jul 22 20:47:54 UTC 2005 soda@srapc2586:/usr/src/sys/arch/i386/compile/PC i386
Architecture: i386
Machine: i386
>Description:
tsocks-1.8beta5 doesn't work with NetBSD's stock ftp client (in passive mode)
>How-To-Repeat:
Try the following command, and see it fails.
% tsocks ftp <hostname>
>Fix:
There are 2 serious bugs in poll() implementation and 1 portability
problem in connect() implementation.
1. poll() bug #1
tsocks assumes that flags in struct connreq::selectevents are
compatible with flags in struct pollfd::events, because tsocks.c
line 551 and line 675 directly assign these struct members each other.
but the assumption is wrong as follows:
connreq::selectevents pollfd::events (on Solaris, Linux, NetBSD,)
READ 0x01 POLLIN 0x1
WRITE 0x02 POLLOUT 0x4
EXCEPT 0x04 POLLPRI 0x2
also, POLLRDNORM should be treated as READ,
POLLWRNORM and POLLWRBAND should be treated as WRITE,
and POLLRDBAND should be treated as EXCEPT, as well.
At least the WRITE case is really critical, because that's refered in
line 660 of tsocks.c.
the patch to tsocks.h in the attached file fixes this problem.
2. poll() bug #2
if connection is established and the client is polling for writing,
struct pollfd:revents doesn't correctly updated.
the patch to poll() implementation in the attached file fixes this problem.
3. connect() portability problem
on NetBSD and some other operating systems, if once connect(2) is
called with non-blocking mode, subsequent connect(2) call to same
descriptor doesn't return 0, rather it returns EINPROGRESS
(Operation now in progress) or EISCONN (Socket is already connected).
The connect() implementation in tsocks already deals with the
EINPROGRESS case, but doesn't deal with the EISCONN case.
the patch to connect_server() function in the attached file fixes
this problem.
perhaps it's better to use "#if defined(__NetBSD__)" in this case,
but I guess this patch isn't so harmful on other OS.
P.S.
I already reported this problem to the tsocks project in sourcefoge
as follows:
https://sourceforge.net/tracker/index.php?func=detail&aid=1252703&group_id=17338&atid=117338
Index: tsocks.h
*** tsocks.h- Wed Mar 13 21:58:09 2002
--- tsocks.h Sat Aug 6 01:01:52 2005
***************
*** 75,83 ****
#define FAILED 14
/* Flags to indicate what events a socket was select()ed for */
! #define READ (1<<0)
! #define WRITE (1<<1)
! #define EXCEPT (1<<2)
#define READWRITE (READ|WRITE)
#define READWRITEEXCEPT (READ|WRITE|EXCEPT)
--- 75,83 ----
#define FAILED 14
/* Flags to indicate what events a socket was select()ed for */
! #define READ (POLLIN|POLLRDNORM)
! #define WRITE (POLLOUT|POLLWRNORM|POLLWRBAND)
! #define EXCEPT (POLLRDBAND|POLLPRI)
#define READWRITE (READ|WRITE)
#define READWRITEEXCEPT (READ|WRITE|EXCEPT)
Index: tsocks.c
*** tsocks.c- Fri Aug 5 22:03:02 2005
--- tsocks.c Sat Aug 6 01:05:12 2005
***************
*** 658,664 ****
* come around again (since we can't flag it for read, we don't know
* if there is any data to be read and can't be bothered checking) */
if (conn->selectevents & WRITE) {
! setevents |= POLLOUT;
nevents++;
}
}
--- 658,664 ----
* come around again (since we can't flag it for read, we don't know
* if there is any data to be read and can't be bothered checking) */
if (conn->selectevents & WRITE) {
! ufds[i].revents |= POLLOUT;
nevents++;
}
}
***************
*** 852,858 ****
sizeof(conn->serveraddr));
show_msg(MSGDEBUG, "Connect returned %d, errno is %d\n", rc, errno);
! if (rc) {
if (errno != EINPROGRESS) {
show_msg(MSGERR, "Error %d attempting to connect to SOCKS "
"server (%s)\n", errno, strerror(errno));
--- 852,862 ----
sizeof(conn->serveraddr));
show_msg(MSGDEBUG, "Connect returned %d, errno is %d\n", rc, errno);
! if (rc && errno == EISCONN) {
! rc = 0;
! show_msg(MSGDEBUG, "Socket %d already connected to SOCKS server\n", conn->sockid);
! conn->state = CONNECTED;
! } else if (rc) {
if (errno != EINPROGRESS) {
show_msg(MSGERR, "Error %d attempting to connect to SOCKS "
"server (%s)\n", errno, strerror(errno));
>Release-Note:
>Audit-Trail:
From: SODA Noriyuki <soda@sra.co.jp>
To: gnats-bugs@NetBSD.org
Cc: pkgsrc-bugs@NetBSD.org
Subject: Re: pkg/30921: tsocks doesn't work with tnftp client (patch included)
Date: Sat, 6 Aug 2005 03:01:35 +0900 (JST)
Second thought...
>>>>> On Fri, 5 Aug 2005 17:19:00 +0000 (UTC),
SODA Noriyuki <soda@NetBSD.org> said:
> if (conn->selectevents & WRITE) {
> ! ufds[i].revents |= POLLOUT;
> nevents++;
It's better to use the following change:
ufds[i].revents |= (conn->selectevents & WRITE);
instead of above "ufds[i].revents |= POLLOUT;".
--
soda
Responsible-Changed-From-To: pkg-manager->jmmv
Responsible-Changed-By: recht@netbsd.org
Responsible-Changed-When: Sat, 06 Aug 2005 18:51:19 +0000
Responsible-Changed-Why:
over to maintainer
State-Changed-From-To: open->closed
State-Changed-By: jmmv@netbsd.org
State-Changed-When: Sun, 17 Sep 2006 11:46:01 +0000
State-Changed-Why:
Changes applied. Thanks!
From: "Julio M. Merino Vidal" <jmmv@netbsd.org>
To: gnats-bugs@NetBSD.org
Cc:
Subject: PR/30921 CVS commit: pkgsrc/net/tsocks
Date: Sun, 17 Sep 2006 11:45:04 +0000 (UTC)
Module Name: pkgsrc
Committed By: jmmv
Date: Sun Sep 17 11:45:04 UTC 2006
Modified Files:
pkgsrc/net/tsocks: Makefile distinfo
pkgsrc/net/tsocks/patches: patch-ac
Added Files:
pkgsrc/net/tsocks/patches: patch-ad
Log Message:
Fix serious portability issues (to NetBSD) as regards poll(2) usage.
This change lets, e.g. tnftp work when using tsocks. From soda@ in
PR pkg/30921. Bump PKGREVISION to 2.
To generate a diff of this commit:
cvs rdiff -r1.10 -r1.11 pkgsrc/net/tsocks/Makefile
cvs rdiff -r1.5 -r1.6 pkgsrc/net/tsocks/distinfo
cvs rdiff -r1.1 -r1.2 pkgsrc/net/tsocks/patches/patch-ac
cvs rdiff -r0 -r1.1 pkgsrc/net/tsocks/patches/patch-ad
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
>Unformatted:
(Contact us)
$NetBSD: query-full-pr,v 1.51 2026/08/10 02:28:17 riastradh Exp $
$NetBSD: gnats_config.sh,v 1.10 2026/05/13 22:00:09 riastradh Exp $
Copyright © 1994-2026
The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.