Skip to Content.
Sympa Menu

freetds - Re: Bug#138166: freetds0: freetds enters infinite loop if connection dropped unexpectedly

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: Steve Langasek <vorlon AT netexpress.net>
  • To: Colin Phipps <cph AT netcraft.com>, 138166 AT bugs.debian.org
  • Cc: TDS Development Group <freetds AT franklin.metalab.unc.edu>
  • Subject: Re: Bug#138166: freetds0: freetds enters infinite loop if connection dropped unexpectedly
  • Date: Wed, 13 Mar 2002 12:48:19 -0600

Hi Colin,

On Wed, Mar 13, 2002 at 04:18:32PM +0000, Colin Phipps wrote:
> Freetds does not recognise a return value of 0 from read(2) indicating
> that the connection has been closed by the remote. This results in an
> infinite loop if the remote system drops the connection unexpectedly.

> Something like the following would cause an unexpected connection drop
> to be treated as an error:

Given that the only time we'll have zero bytes available for reading is if
the declared timeout has been exceeded, this seems an acceptable solution.
It might also be beneficial to actively watch the socket for exceptions, so
we don't have to wait for the timeout when we know the socket is closed.

The second part of the patch looks ok, although better handling for EINTR
should really be in order (in both versions of the loop).

I'm CC:ing the upstream mailing list for comments, and will apply the patch
upstream and to the Debian packages if there are no objections.

Thanks,
Steve Langasek
postmodern programmer

> --- freetds-0.53/src/tds/read.c Wed Mar 13 16:06:03 2002
> +++ freetds-0.53-cph1/src/tds/read.c Wed Mar 13 15:12:26 2002
> @@ -74,7 +74,7 @@ struct timeval selecttimeout;
> }
> len = READ(tds->s, buf+got, buflen);
>
> - if (len < 0) {
> + if (len <= 0) {
> return (-1); /* SOCKET_ERROR); */
> }
>
> @@ -91,7 +91,11 @@ struct timeval selecttimeout;
> } else {
> /* got = READ(tds->s, buf, buflen); */
> while (got < buflen) {
> - got += READ(tds->s, buf + got, buflen - got);
> + int len = READ(tds->s, buf + got, buflen - got);
> + if (len <= 0) {
> + return (-1); /* SOCKET_ERROR); */
> + }
> + got += len;
> }
>
> }
>
> Note that the timeout-less version of the loop doesn't even handle
> other types of read error correctly without this patch...
>
> This is tested to fix my specific case, but hasn't been tested much
> otherwise.
>
> -- System Information
> Debian Release: 3.0
> Architecture: i386
> Kernel: Linux nausea.netcraft.com 2.4.18 #1 Tue Feb 26 10:31:34 GMT 2002
> i686
> Locale: LANG=en_GB, LC_CTYPE=en_GB
>
> Versions of packages freetds0 depends on:
> ii debconf 1.0.26 Debian configuration
> management sy
> ii libc6 2.2.5-3 GNU C Library: Shared
> libraries an
> ii libglib1.2 1.2.10-4 The GLib library of C routines
>
> --
> Colin Phipps PGP 0x689E463E http://www.netcraft.com/

Attachment: pgpLGe74qzG6t.pgp
Description: PGP signature



  • Re: Bug#138166: freetds0: freetds enters infinite loop if connection dropped unexpectedly, Steve Langasek, 03/13/2002

Archive powered by MHonArc 2.6.24.

Top of Page