Bug 170503 - freebsd-update(8) mirror finding is case sensitive
Summary: freebsd-update(8) mirror finding is case sensitive
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: Unspecified
Hardware: Any Any
: Normal Affects Only Me
Assignee: Colin Percival
URL:
Keywords:
: 197047 213411 (view as bug list)
Depends on:
Blocks:
 
Reported: 2012-08-09 15:50 UTC by Wybe van der Ham
Modified: 2018-03-04 08:00 UTC (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Wybe van der Ham 2012-08-09 15:50:01 UTC
The freebsd-update script tries to find mirrors using SRV records. My Mikrotik router with built-in nameserver gives the following output:
# host -t srv _http._tcp.update.FreeBSD.org
_http._tcp.update.freebsd.org has SRV record 1 35 80 update4.FreeBSD.org.
_http._tcp.update.freebsd.org has SRV record 1 50 80 update5.FreeBSD.org.
_http._tcp.update.freebsd.org has SRV record 1 5 80 update3.FreeBSD.org.

The first part is converted to lowercase. The freebsd-update script checks (with sed) for "_http._tcp.update.FreeBSD.org", but that does not match the lowercase output.
freebsd-update is unable to find the mirrors, and freebsd-update fails.

The workaround for this problem is to change the Servername in /etc/freebsd-update.conf to all lowercase.

Fix: 

Make the regular expression - used to strip away the "_http._tcp.update.freebsd.org has SRV record " - case insensitive:

Change:
sed -nE "s/${MLIST} (has SRV record|server selection) //p"
to
sed -nE "s/${MLIST} (has SRV record|server selection) //Ip"
How-To-Repeat: Use a mikrotik router as nameserver or any other nameserver that returns the requested hostname in lowercase instead of the original casing.
Comment 1 Mark Linimon freebsd_committer freebsd_triage 2014-04-14 00:24:27 UTC
Responsible Changed
From-To: freebsd-bugs->cperciva

Over to maintainer.
Comment 2 Joseph Mulloy 2015-05-20 16:13:09 UTC
I'm also seeing this on 10.1-Release with BIND 9 as my DNS server.

$ host -t srv _http._tcp.update.FreeBSD.org
_http._tcp.update.FreeBSD.org has SRV record 1 30 80 update2.freebsd.org.
_http._tcp.update.FreeBSD.org has SRV record 1 40 80 update6.freebsd.org.
_http._tcp.update.FreeBSD.org has SRV record 1 5 80 update3.freebsd.org.
_http._tcp.update.FreeBSD.org has SRV record 1 35 80 update4.freebsd.org.
_http._tcp.update.FreeBSD.org has SRV record 1 50 80 update5.freebsd.org.

$ host -t srv _http._tcp.update.FreeBSD.org | sed -nE "s/_http._tcp.update.FreeBSD.org (has SRV record|server selection) //p"

$ host -t srv _http._tcp.update.FreeBSD.org | sed -nE "s/_http._tcp.update.FreeBSD.org (has SRV record|server selection) //pi"
1 50 80 update5.freebsd.org.
1 35 80 update4.freebsd.org.
1 40 80 update6.freebsd.org.
1 30 80 update2.freebsd.org.
1 5 80 update3.freebsd.org.
Comment 3 Colin Percival freebsd_committer freebsd_triage 2015-05-20 16:26:21 UTC
Joseph: I must be blind... looks to me like that `host` output should be matched even with case sensitivity?
Comment 4 Mark Linimon freebsd_committer freebsd_triage 2015-05-20 16:33:12 UTC
*** Bug 197047 has been marked as a duplicate of this bug. ***
Comment 5 John Michael 2016-10-12 00:03:26 UTC
(In reply to Colin Percival from comment #3)

bind cache's only the first result's case to save space, so subsequent requests that require case sensitivity in post-processing will potentially fail.

To work around this issue, I had to add "no-case-compress { any; };" to my options section in named.conf.
Comment 6 Andrey Kiryanov 2016-10-12 07:56:56 UTC
The bug is still there in 11.0-RELEASE
Silly enough the very same code is implemented properly in portsnap.

Compare fetch_pick_server_init() functions in portsnap and freebsd-update. The only difference is capital 'i' option in sed expression which is missing from freebsd-update and triggering this bug for ages.
Comment 7 commit-hook freebsd_committer freebsd_triage 2016-10-12 20:25:02 UTC
A commit references this bug:

Author: cperciva
Date: Wed Oct 12 20:24:33 UTC 2016
New revision: 307156
URL: https://svnweb.freebsd.org/changeset/base/307156

Log:
  MFportsnap r264740: Use case insensitive match when parsing host(1) output.

  Some DNS caches turn "FreeBSD.org" into "freebsd.org", which was causing
  the printed SRV records to not match our regex.

  PR:		170503
  MFC after:	2 weeks

Changes:
  head/usr.sbin/freebsd-update/freebsd-update.sh
Comment 8 Colin Percival freebsd_committer freebsd_triage 2016-10-12 20:26:25 UTC
(In reply to John Michael from comment #5)

Aha!  Thanks for pointing out the dns cache mangling... I couldn't figure out how this was happening (or to reproduce it myself, given that I don't use that particular cache).

Should be fixed now, will MFC in a couple weeks.
Comment 9 Colin Percival freebsd_committer freebsd_triage 2016-10-15 19:49:17 UTC
*** Bug 213411 has been marked as a duplicate of this bug. ***
Comment 10 commit-hook freebsd_committer freebsd_triage 2018-03-04 08:00:43 UTC
A commit references this bug:

Author: eadler
Date: Sun Mar  4 08:00:07 UTC 2018
New revision: 330373
URL: https://svnweb.freebsd.org/changeset/base/330373

Log:
  MFC r307156:

  MFportsnap r264740: Use case insensitive match when parsing host(1) output.

  Some DNS caches turn "FreeBSD.org" into "freebsd.org", which was causing
  the printed SRV records to not match our regex.

  PR:		170503

Changes:
_U  stable/11/
  stable/11/usr.sbin/freebsd-update/freebsd-update.sh