# Why does checkdnsrr() default to MX??

- Thread: https://externals.io/message/77314
- Original archive: https://news-web.php.net/php.internals/77314
- Started by Kris Craig on 2014-09-18T19:29:17+00:00
- Messages: 5
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #77314 — Kris Craig — 2014-09-18T19:29:17+00:00

URL: https://externals.io/message/77314#77314

Hey guys,

I just spent some time troubleshooting what appeared to be a DNS issue
before I realized that, absent the optional $type argument, `checkdnsrr()`
defaults to "MX".  Can anybody explain why it's defaulting to "MX" and not
"ANY"?  It seems really counter-intuitive.

--Kris

---

## #77331 — Chris Wright — 2014-09-19T09:58:19+00:00

URL: https://externals.io/message/77314#77331 · In reply to: #77314

> Hey guys,
>
> I just spent some time troubleshooting what appeared to be a DNS issue
> before I realized that, absent the optional $type argument, `checkdnsrr()`
> defaults to "MX".  Can anybody explain why it's defaulting to "MX" and not
> "ANY"?  It seems really counter-intuitive.
>
> --Kris

This is a big wtf, especially since `getmxrr()` exists. A cursory search
of github (not the best measure I know, but easy) reveals only a few
cases where this function is called without the second argument, and
every case I've found looks like they were expecting an A record, so
this code is likely broken anyway.

In other words, +1 to change this to something saner ASAP.

---

## #77346 — Adam Harvey — 2014-09-19T17:24:31+00:00

URL: https://externals.io/message/77314#77346 · In reply to: #77331

> 
> > […]
>
> This is a big wtf, especially since `getmxrr()` exists. A cursory search
> of github (not the best measure I know, but easy) reveals only a few
> cases where this function is called without the second argument, and
> every case I've found looks like they were expecting an A record, so
> this code is likely broken anyway.
>
> In other words, +1 to change this to something saner ASAP.

As an alternative, could we just make the type argument mandatory in
PHP 7 and start issuing `E_DEPRECATED` warnings if it's omitted in 5.6
or 5.7?

Adam

---

## #77347 — Kris Craig — 2014-09-19T17:51:05+00:00

URL: https://externals.io/message/77314#77347 · In reply to: #77346

> 
> > […]
> not
> > […]
>
> As an alternative, could we just make the type argument mandatory in
> PHP 7 and start issuing `E_DEPRECATED` warnings if it's omitted in 5.6
> or 5.7?
>
> Adam
>

I like both ideas.  Adam's approach would be more inconvenient for
developers, but it would also be less of a BC issue since merely changing
the default could cause some existing code to fail silently as opposed to
generating an error.  On the other hand, I can't think of any such use case
in which checking all DNS entries instead of just MX would cause any
scripts to break.  The only possible scenario I can think of would be if
they're using dnsrr() to check if an MX record exists and hit a host that
has an A record but not MX.  That would cause it to return `TRUE` when
they're expecting FALSE.

I'll draft an RFC when I get a chance and include both options in it.

--Kris

---

## #77348 — Adam Harvey — 2014-09-19T17:54:30+00:00

URL: https://externals.io/message/77314#77348 · In reply to: #77347

> 
> > […]
>
> I like both ideas.  Adam's approach would be more inconvenient for
> developers, but it would also be less of a BC issue since merely changing
> the default could cause some existing code to fail silently as opposed to
> generating an error.  On the other hand, I can't think of any such use case
> in which checking all DNS entries instead of just MX would cause any scripts
> to break.  The only possible scenario I can think of would be if they're
> using dnsrr() to check if an MX record exists and hit a host that has an A
> record but not MX.  That would cause it to return `TRUE` when they're
> expecting FALSE.

I'm not a huge fan of silently making it ANY for the reason Sanford
explained elsethread — it's a potential vector for amplification
attacks. I also don't think it's unreasonable to expect developers to
know what type of record they're interested in. :)

> I'll draft an RFC when I get a chance and include both options in it.

Thanks!

Adam
