Bug 212122 - [PATCH] getaddrinfo doesn't implement sort rule 10 deterministically
Summary: [PATCH] getaddrinfo doesn't implement sort rule 10 deterministically
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Many People
Assignee: Andrey A. Chernov
URL:
Keywords: patch
Depends on:
Blocks:
 
Reported: 2016-08-24 20:04 UTC by Herbie.Robinson
Modified: 2016-08-30 01:04 UTC (History)
1 user (show)

See Also:
ache: mfc-stable11+
ache: mfc-stable10+


Attachments
patch for Revision 304034 (head) (1.28 KB, patch)
2016-08-24 20:07 UTC, Herbie.Robinson
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Herbie.Robinson 2016-08-24 20:04:38 UTC
The formal behavior of qsort is unstable with regard to objects that are equal.  Unfortunately, the standard requires that otherwise equal objects remain in the order supplied by the DNS server.  The present code attempts to deal with this by returning -1 for objects that are equal (i.e., returns that the first parameter is less then the second parameter).  Unfortunately, the qsort API does not state that the first parameter passed in is in any particular position in the list.

Assuming I can get it uploaded, the patch I have for it will be against Revision 304034.

Again, while this affects a lot or people, I don't think many will notice.  It's been this way for years and I only just noticed...
Comment 1 Herbie.Robinson 2016-08-24 20:07:46 UTC
Created attachment 174026 [details]
patch for Revision 304034 (head)
Comment 2 Herbie.Robinson 2016-08-24 20:09:07 UTC
irc.warped.net is a good test case for this...  Turn on debug and make sure the getaddrinfo results are sorted the same way they come from DNS (which changes every time).
Comment 3 commit-hook freebsd_committer freebsd_triage 2016-08-27 14:43:30 UTC
A commit references this bug:

Author: ache
Date: Sat Aug 27 14:43:13 UTC 2016
New revision: 304911
URL: https://svnweb.freebsd.org/changeset/base/304911

Log:
  The formal behavior of qsort is unstable with regard to objects that
  are equal. Unfortunately, RFC 3484 requires that otherwise equal objects
  remain in the order supplied by the DNS server. The present code attempts
  to deal with this by returning -1 for objects that are equal (i.e.,
  returns that the first parameter is less then the second parameter).
  Unfortunately, the qsort API does not state that the first parameter
  passed in is in any particular position in the list.

  PR:     212122
  Submitted by:   Herbie.Robinson@stratus.com
  MFC after:      3 days

Changes:
  head/lib/libc/net/getaddrinfo.c
Comment 4 commit-hook freebsd_committer freebsd_triage 2016-08-30 00:58:19 UTC
A commit references this bug:

Author: ache
Date: Tue Aug 30 00:57:57 UTC 2016
New revision: 305037
URL: https://svnweb.freebsd.org/changeset/base/305037

Log:
  MFC r304911

  The formal behavior of qsort is unstable with regard to objects that
  are equal. Unfortunately, RFC 3484 requires that otherwise equal objects
  remain in the order supplied by the DNS server. The present code attempts
  to deal with this by returning -1 for objects that are equal (i.e.,
  returns that the first parameter is less then the second parameter).
  Unfortunately, the qsort API does not state that the first parameter
  passed in is in any particular position in the list.

  PR:     212122
  Submitted by:   Herbie.Robinson@stratus.com

Changes:
_U  stable/10/
  stable/10/lib/libc/net/getaddrinfo.c
Comment 5 commit-hook freebsd_committer freebsd_triage 2016-08-30 01:02:21 UTC
A commit references this bug:

Author: ache
Date: Tue Aug 30 01:01:42 UTC 2016
New revision: 305038
URL: https://svnweb.freebsd.org/changeset/base/305038

Log:
  MFC r304911

  The formal behavior of qsort is unstable with regard to objects that
  are equal. Unfortunately, RFC 3484 requires that otherwise equal objects
  remain in the order supplied by the DNS server. The present code attempts
  to deal with this by returning -1 for objects that are equal (i.e.,
  returns that the first parameter is less then the second parameter).
  Unfortunately, the qsort API does not state that the first parameter
  passed in is in any particular position in the list.

  PR:     212122
  Submitted by:   Herbie.Robinson@stratus.com

Changes:
_U  stable/11/
  stable/11/lib/libc/net/getaddrinfo.c