From: marcus at synchromedia dot co dot uk Operating system: OS X PHP version: 5.4.18 Package: Network related Bug Type: Bug Bug description:Multi-string DNS records obtained with dns_get_record contain nulls
Description: ------------ RFC4408 (SPF records in DNS) http://www.ietf.org/rfc/rfc4408.txt section 3.1.3 mentions the likely use of RFC1035's provision to allow a DNS record to contain more than one string. Specifically it says: For example: IN TXT "v=spf1 .... first" "second string..." MUST be treated as equivalent to IN TXT "v=spf1 .... firstsecond string..." PHP's dns_get_record function does NOT work this way - it concatenates the strings, but inserts a null (\0) character between them, so in this example it would produce this string: IN TXT "v=spf1 .... first\0second string..." This is enough to break things like DKIM. The example code uses the DKIM key for google groups. Notice that the string length in the actual result is off by one: the two entries are 183 and 218 chars, which should give 401 when concatenated, but there are 402 chars in the result. The '\0' is visible in this result, but in some circumstances it may not be visible. I've seen this behaviour on all platforms (OS X, Linux) and versions (5.3, 5.4) I've tried. A workaround is to strip the null from the resource record: $rr = str_replace("\0", '', $rr); The returned value from the dns_get_record includes the original separate strings under the 'entries' key, so there's no benefit in keeping the nulls for the purpose of being able to separate the strings. This bug is related to bug #54821, but is not a dupe of it. Test script: --------------- var_dump(dns_get_record("20120806._domainkey.googlegroups.com", DNS_TXT)); Expected result: ---------------- array(1) { [0] => array(6) { 'host' => string(36) "20120806._domainkey.googlegroups.com" 'class' => string(2) "IN" 'ttl' => int(4502) 'type' => string(3) "TXT" 'txt' => string(401) "k=rsa; p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAzb2fhKQxJYmlF+PNnOExrd8kRMlV2b/GBb 1mw4vpTGDVS8wD+6k8TEXSSsaS2B4uOrOfKBWBb6lMVbVmi/zy3Jc+YP5XkEt09UtXm4HWeAqgu0arqC mjH6yhbUGlPipIqV00QMmWy5jnWJsHioAAN8G5S5t5qrCRzxv7ntDOOUhwEPCIIrfncOgBzF4XdJPiua nUNOX5Jw5Q2H3wcOmBTKQ3t0ETvPYK/cqpe7rJ+4L06+QKE2kk/WDuHuxtSZbZUo2U6kM56CGxdvBiNR fPLoMFnMddCQqXYJsJZJHfwBnLQxFwbkZS0idkSWLf8AUKbB0lVWQe4+F0M1CeOj8YimmQIDAQAB" 'entries' => array(2) { [0] => string(183) "k=rsa; p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAzb2fhKQxJYmlF+PNnOExrd8kRMlV2b/GBb 1mw4vpTGDVS8wD+6k8TEXSSsaS2B4uOrOfKBWBb6lMVbVmi/zy3Jc+YP5XkEt09UtXm4HWeAqgu0arqC mjH6yhbUGlPipIqV" [1] => string(218) "QMmWy5jnWJsHioAAN8G5S5t5qrCRzxv7ntDOOUhwEPCIIrfncOgBzF4XdJPiuanUNOX5Jw5Q2H3wcOm BTKQ3t0ETvPYK/cqpe7rJ+4L06+QKE2kk/WDuHuxtSZbZUo2U6kM56CGxdvBiNRfPLoMFnMddCQqXYJs JZJHfwBnLQxFwbkZS0idkSWLf8AUKbB0lVWQe4+F0M1CeOj8YimmQIDAQAB" } } } Actual result: -------------- array(1) { [0] => array(6) { 'host' => string(36) "20120806._domainkey.googlegroups.com" 'class' => string(2) "IN" 'ttl' => int(4502) 'type' => string(3) "TXT" 'txt' => string(402) "k=rsa; p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAzb2fhKQxJYmlF+PNnOExrd8kRMlV2b/GBb 1mw4vpTGDVS8wD+6k8TEXSSsaS2B4uOrOfKBWBb6lMVbVmi/zy3Jc+YP5XkEt09UtXm4HWeAqgu0arqC mjH6yhbUGlPipIqV\000QMmWy5jnWJsHioAAN8G5S5t5qrCRzxv7ntDOOUhwEPCIIrfncOgBzF4XdJPi uanUNOX5Jw5Q2H3wcOmBTKQ3t0ETvPYK/cqpe7rJ+4L06+QKE2kk/WDuHuxtSZbZUo2U6kM56CGxdvBi NRfPLoMFnMddCQqXYJsJZJHfwBnLQxFwbkZS0idkSWLf8AUKbB0lVWQe4+F0M1CeOj8YimmQIDAQAB" 'entries' => array(2) { [0] => string(183) "k=rsa; p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAzb2fhKQxJYmlF+PNnOExrd8kRMlV2b/GBb 1mw4vpTGDVS8wD+6k8TEXSSsaS2B4uOrOfKBWBb6lMVbVmi/zy3Jc+YP5XkEt09UtXm4HWeAqgu0arqC mjH6yhbUGlPipIqV" [1] => string(218) "QMmWy5jnWJsHioAAN8G5S5t5qrCRzxv7ntDOOUhwEPCIIrfncOgBzF4XdJPiuanUNOX5Jw5Q2H3wcOm BTKQ3t0ETvPYK/cqpe7rJ+4L06+QKE2kk/WDuHuxtSZbZUo2U6kM56CGxdvBiNRfPLoMFnMddCQqXYJs JZJHfwBnLQxFwbkZS0idkSWLf8AUKbB0lVWQe4+F0M1CeOj8YimmQIDAQAB" } } } -- Edit bug report at https://bugs.php.net/bug.php?id=65478&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=65478&r=trysnapshot54 Try a snapshot (PHP 5.3): https://bugs.php.net/fix.php?id=65478&r=trysnapshot53 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=65478&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=65478&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=65478&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=65478&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=65478&r=needscript Try newer version: https://bugs.php.net/fix.php?id=65478&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=65478&r=support Expected behavior: https://bugs.php.net/fix.php?id=65478&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=65478&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=65478&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=65478&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=65478&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=65478&r=dst IIS Stability: https://bugs.php.net/fix.php?id=65478&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=65478&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=65478&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=65478&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=65478&r=mysqlcfg