From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10093 invoked by alias); 1 Oct 2009 23:53:06 -0000 Received: (qmail 10083 invoked by uid 22791); 1 Oct 2009 23:53:06 -0000 X-SWARE-Spam-Status: No, hits=-2.5 required=5.0 tests=AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from snvl-smtp1.trimble.com (HELO snvl-smtp1.trimble.com) (155.63.64.31) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 01 Oct 2009 23:53:01 +0000 Received: (qmail 11506 invoked by uid 501); 1 Oct 2009 16:53:00 -0700 Received: from 10.1.184.31 by snvl-smtp1.trimble.com (envelope-from , uid 108) with qmail-scanner-2.07 (clamdscan: 0.95.2/9859. sophie: 3.06/2.90.1/4.45. spamassassin: 3.2.5. Clear:RC:1(10.1.184.31):. Processed in 0.011993 secs); 01 Oct 2009 23:53:00 -0000 Received: from unknown (HELO uss-am-xch-01.am.trimblecorp.net) (10.1.184.31) by snvl-smtp1.trimble.com with SMTP; 1 Oct 2009 16:52:59 -0700 Received: from uss-am-xch-02.am.trimblecorp.net ([10.1.184.32]) by uss-am-xch-01.am.trimblecorp.net with Microsoft SMTPSVC(6.0.3790.1830); Thu, 1 Oct 2009 16:52:38 -0700 Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: quoted-printable Date: Thu, 01 Oct 2009 23:53:00 -0000 Message-ID: In-Reply-To: <4AC53D59.9010401@systech.com> References: <4AC53D59.9010401@systech.com> From: "Will Lentz" To: "Jay Foster" Cc: Mailing-List: contact ecos-discuss-help@ecos.sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: ecos-discuss-owner@ecos.sourceware.org Subject: RE: [ECOS] 'id' rollover bug in dns.c X-SW-Source: 2009-10/txt/msg00009.txt.bz2 Thanks! That's a better solution. Will=20 -----Original Message----- From: Jay Foster [mailto:jay@systech.com]=20 Sent: Thursday, October 01, 2009 4:38 PM To: Will Lentz Cc: ecos-discuss@ecos.sourceware.org Subject: Re: [ECOS] 'id' rollover bug in dns.c I discovered that issue some time ago and resolved it in a different=20 manner that also allows multiple concurrent DNS queries to be sent from=20 different threads. The solution was to change the declaration of 'id'=20 to be unsigned to match the definition of id in the dns_header structure. -static short id =3D 0; +static unsigned short id =3D 0; Then declare a new variable in send_recv() unsigned short req_id; Then assign this variable with the ID value contained in the DNS request dns_hdr =3D (struct dns_header *) &msg_buf[0]; + req_id =3D ((struct dns_header *)msg)->id; do { /* Send a request to each configured DNS server */ Then compare the ID in the responses with req_id if (dns_hdr->id !=3D req_id) { continue; } This avoids ignoring valid DNS responses when the global variable, id,=20 is incremented by another concurrent DNS request. Jay On 10/1/2009 4:11 PM, Will Lentz wrote: > Hi, > > There is a rollover bug in the current CVS copy of dns.c. Around line > 237 there is the following code: > /* Reply to an old query. Ignore it */ > if (ntohs(dns_hdr->id) !=3D (id-1)) { > > If dns_hdr->id =3D=3D 5 and id =3D=3D 6, then the 'if' condition is false= as > expected. > > If dns_hdr->id =3D=3D 0xFFFF and id =3D=3D 0, then the 'if' condition is > incorrectly true. > > The simple patch below fixes the issue: > --- dns_old.c 2009-10-01 16:01:41.000000000 -0700 > +++ dns.c 2009-10-01 16:01:45.000000000 -0700 > @@ -234,7 +234,7 @@ > } > > /* Reply to an old query. Ignore it */ > - if (ntohs(dns_hdr->id) !=3D (id-1)) { > + if (ntohs(dns_hdr->id) !=3D (cyg_uint16)(id-1)) { > continue; > } > finished =3D true; > > > Cheers, > Will > >=20=20=20=20 -- Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss