<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "http://sourceware.org/bugzilla/bugzilla.dtd">

<bugzilla version="4.0.10"
          urlbase="http://sourceware.org/bugzilla/"
          
          maintainer="overseers@sourceware.org"
>

    <bug>
          <bug_id>13013</bug_id>
          
          <creation_ts>2011-07-21 16:46:00 +0000</creation_ts>
          <short_desc>assertion error in res_query.c</short_desc>
          <delta_ts>2012-11-30 20:05:56 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>glibc</product>
          <component>network</component>
          <version>2.16</version>
          <rep_platform>All</rep_platform>
          <op_sys>All</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>2.17</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Aurelien Jarno">aurelien</reporter>
          <assigned_to name="Ulrich Drepper">drepper.fsp</assigned_to>
          <cc>allan</cc>
    
    <cc>bugzilla</cc>
    
    <cc>davem</cc>
    
    <cc>law</cc>
    
    <cc>mmarek</cc>
    
    <cc>nick.jones</cc>
    
    <cc>pluto</cc>
    
    <cc>timothy.c.pepper</cc>
    
    <cc>toolchain</cc>
          <cf_gcchost></cf_gcchost>
          <cf_gcctarget></cf_gcctarget>
          <cf_gccbuild></cf_gccbuild>
          

      

      

      

          <long_desc isprivate="0">
            <commentid>49962</commentid>
              <attachid>5855</attachid>
            <who name="Aurelien Jarno">aurelien</who>
            <bug_when>2011-07-21 16:46:14 +0000</bug_when>
            <thetext>Created attachment 5855
Patch to fix the issue

Commit 4769ae77fc6c8dacea6476addb015c8797848cdd a regression in the resolver code, which trigger an assert in some conditions:

firefox-bin: res_query.c:251: __libc_res_nquery: Assertion `hp != hp2&apos; failed. Aborting.

When the first answer is a SERVFAIL, NOTIMP or REFUSED, resplen now got assigned 0, while recvresp1 or recvresp2 is set to 1:

  /* No data from the first reply.  */
  resplen = 0;

When the second answer arrives, its buffer is allocated at *ansp + resplen, which means in that case *ansp and *ansp2 are equals:

  *anssizp2 = orig_anssizp - resplen;
  *ansp2 = *ansp + resplen;

Given a second answer has still be provided, hp2 got assigned *answerp2, which is the same than *answer (see above), so hp == hp2.

  HEADER *hp2 = answerp2 ? (HEADER *) *answerp2 : hp;

This is enough to trigger the assertion, that is the checks on the answer buffers doesn&apos;t match the checks on the response lengths.

One way to fix that is to rewrite this part of the code to do all the checks on the response lenghts. This is what the attached patch does.</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <commentid>52222</commentid>
              <attachid>6118</attachid>
            <who name="Fernando Herrera">fherrera</who>
            <bug_when>2011-12-19 03:22:03 +0000</bug_when>
            <thetext>Created attachment 6118
testcase for this bug

This testcase triggers the bug using these nameservers:

nameserver 87.216.1.65
nameserver 87.216.1.66</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <commentid>52297</commentid>
            <who name="Ulrich Drepper">drepper.fsp</who>
            <bug_when>2011-12-22 00:04:28 +0000</bug_when>
            <thetext>(In reply to comment #1)
&gt; Created attachment 6118 [details]
&gt; testcase for this bug
&gt; 
&gt; This testcase triggers the bug using these nameservers:
&gt; 
&gt; nameserver 87.216.1.65
&gt; nameserver 87.216.1.66

No, it doesn&apos;t.  I don&apos;t see any assert.</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <commentid>55279</commentid>
            <who name="">bugzilla</who>
            <bug_when>2012-05-17 18:38:26 +0000</bug_when>
            <thetext>I see this too (as does everyone else who uses a non-patched glibc). Hope to see this fixed in 2.15.1</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <commentid>57888</commentid>
            <who name="Tim Pepper">timothy.c.pepper</who>
            <bug_when>2012-10-09 21:33:47 +0000</bug_when>
            <thetext>I was lazy and edited an scp command in my shell history to be an ssh command, but forgot to remove the &apos;:&apos;, eg:

   scp file host:/big/long/path
   ssh host: command /big/long/path

That ssh command resulted in the assert noted here, but only on a first try.  I&apos;m guessing the query/result is cached and traverses different code subsequently and gives a more expected output like:

   ssh: Could not resolve hostname host:: Name or service not known</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <commentid>57892</commentid>
            <who name="">law</who>
            <bug_when>2012-10-10 00:31:40 +0000</bug_when>
            <thetext>Tim, what are the contents of your resolv.conf?  

This issue is highly dependent on the nameservers you use and unfortunately nobody&apos;s been able to trigger on public nameservers.  I worked with  Fernando on analysis in the past, but wasn&apos;t able to wrap up before having to switch to another issue.</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <commentid>57915</commentid>
            <who name="Tim Pepper">timothy.c.pepper</who>
            <bug_when>2012-10-10 17:28:47 +0000</bug_when>
            <thetext>(In reply to comment #5)
&gt; Tim, what are the contents of your resolv.conf?  

I&apos;m using connman, so my /etc/resolv.conf has simply:
    # Generated by Connection Manager
    nameserver 127.0.0.1

connman&apos;s then using whatever company internal dns server(s) the local corporate dhcp server told it to use...

It&apos;s quite easy for me to reproduce, with the exception of not having figured out what&apos;s being seemingly cached or where.  If there&apos;s anything you&apos;d suggest for added instrumentation in glibc, to look for in the corefile, look for in a tcpdump, etc., let me know and I will dig a layer deeper.</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <commentid>57945</commentid>
            <who name="">law</who>
            <bug_when>2012-10-11 18:35:48 +0000</bug_when>
            <thetext>Unfortunately, we&apos;re obviously not going to be able to access the DNS server running on your local host.

It&apos;s certainly relatively easy to reproduce once you&apos;ve got a nameserver which triggers the problem -- but that&apos;s been the incredibly frustrating problem here.  Every such name server has been behind a firewall.

Given there&apos;s a potential patch attached to this BZ, what&apos;s really needed is for someone with better knowledge of this code to review that patch.  I don&apos;t feel qualified to do that review.</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <commentid>58848</commentid>
            <who name="David S. Miller">davem</who>
            <bug_when>2012-11-30 20:05:56 +0000</bug_when>
            <thetext>Fixed in glibc-2.17</thetext>
          </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
              isurl="0"
          >
            <attachid>5855</attachid>
            <date>2011-07-21 16:46:00 +0000</date>
            <delta_ts>2011-07-21 16:46:14 +0000</delta_ts>
            <desc>Patch to fix the issue</desc>
            <filename>glibc-resolv-assert.diff</filename>
            <type>text/plain</type>
            <size>1843</size>
            <attacher>aurelien</attacher>
            
              <data encoding="base64">MjAxMS0wNy0yMSAgQXVyZWxpZW4gSmFybm8gIDxhdXJlbDMyQGRlYmlhbi5vcmc+CgoJKiByZXNv
bHYvcmVzX3F1ZXJ5LmMoX19saWJjX3Jlc19ucXVlcnkpOiBBc3NpZ24gaHAgYW5kIGhwMiAKCWRl
cGVuZGluZyBuIGFuZCByZXNwbGVuMiB0byBjYXRjaCBjYXNlcyB3aGVyZSBhbnN3ZXIgCgllcXVh
bHMgYW5zd2VycDIuCgpkaWZmIC0tZ2l0IGEvcmVzb2x2L3Jlc19xdWVyeS5jIGIvcmVzb2x2L3Jl
c19xdWVyeS5jCmluZGV4IDJmN2NmYWEuLjQwNWZhNjggMTAwNjQ0Ci0tLSBhL3Jlc29sdi9yZXNf
cXVlcnkuYworKysgYi9yZXNvbHYvcmVzX3F1ZXJ5LmMKQEAgLTEyMiw2ICsxMjIsNyBAQCBfX2xp
YmNfcmVzX25xdWVyeShyZXNfc3RhdGUgc3RhdHAsCiAJCSAgaW50ICpyZXNwbGVuMikKIHsKIAlI
RUFERVIgKmhwID0gKEhFQURFUiAqKSBhbnN3ZXI7CisJSEVBREVSICpocDI7CiAJaW50IG4sIHVz
ZV9tYWxsb2MgPSAwOwogCXVfaW50IG9mbGFncyA9IHN0YXRwLT5fZmxhZ3M7CiAKQEAgLTIzOSwy
NiArMjQwLDI1IEBAIF9fbGliY19yZXNfbnF1ZXJ5KHJlc19zdGF0ZSBzdGF0cCwKIAkgIC8qIF9f
bGliY19yZXNfbnNlbmQgbWln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IHNpemVvZiAoSEVBREVSKSkKKwllbHNlCiAJICB7Ci0JICAgIC8qIFNw
ZWNpYWwgY2FzZSBvZiBwYXJ0aWFsIGFuc3dlci4gICovCi0JICAgIGFzc2VydCAoaHAgIT0gaHAy
KTsKLQkgICAgaHAyID0gaHA7CisJICAgIGhwMiA9IChIRUFERVIgKikgKmFuc3dlcnAyOworCSAg
ICBpZiAobiA8IChpbnQpIHNpemVvZiAoSEVBREVSKSkKKwkgICAgICB7CisJICAgICAgICBocCA9
IGhwMjsKKwkgICAgICB9CiAJICB9CiAKKwkvKiBNYWtlIHN1cmUgYm90aCBocCBhbmQgaHAyIGFy
ZSBkZWZpbmVkICovCisJYXNzZXJ0KChocCAhPSBOVUxMKSAmJiAoaHAyICE9IE5VTEwpKTsKKwog
CWlmICgoaHAtPnJjb2RlICE9IE5PRVJST1IgfHwgbnRvaHMoaHAtPmFuY291bnQpID09IDApCiAJ
ICAgICYmIChocDItPnJjb2RlICE9IE5PRVJST1IgfHwgbnRvaHMoaHAyLT5hbmNvdW50KSA9PSAw
KSkgewogI2lmZGVmIERFQlVHCg==
</data>

          </attachment>
          <attachment
              isobsolete="0"
              ispatch="0"
              isprivate="0"
              isurl="0"
          >
            <attachid>6118</attachid>
            <date>2011-12-19 03:22:00 +0000</date>
            <delta_ts>2011-12-19 03:22:03 +0000</delta_ts>
            <desc>testcase for this bug</desc>
            <filename>testglibcbug.c</filename>
            <type>text/plain</type>
            <size>308</size>
            <attacher>fherrera</attacher>
            
              <data encoding="base64">I2luY2x1ZGUgPHN5cy90eXBlcy5oPgojaW5jbHVkZSA8c3lzL3NvY2tldC5oPgojaW5jbHVkZSA8
bmV0ZGIuaD4KI2luY2x1ZGUgPHVuaXN0ZC5oPgoKaW50IG1haW4gKCkKewoJc3RydWN0IGFkZHJp
bmZvICpyZXMsIGhpbnRzOwoKICAgICAgICBtZW1zZXQoJmhpbnRzLCAwLCBzaXplb2YoaGludHMp
KTsKCWhpbnRzLmFpX2ZsYWdzIHw9IEFJX0FERFJDT05GSUc7CgloaW50cy5haV9zb2NrdHlwZSA9
IFNPQ0tfU1RSRUFNOwoKCWdldGFkZHJpbmZvICgiYnVzY29uLnJhZS5lcyIsIE5VTEwsICZoaW50
cywgJnJlcyk7CglyZXR1cm4gMDsKfQo=
</data>

          </attachment>
      

    </bug>

</bugzilla>