Bind 9.16.11 segfault on DLZ with mysql
Summary
When running bind with DLZ against a mysql database, the system aborts with segfault This database is set up to answer all spam domains
BIND version used
BIND 9.16.11 (Stable Release) id:9ff601b running on Linux x86_64 5.10.17+ #8 (closed) SMP Mon Feb 22 18:54:47 CET 2021 built by make with '--build=x86_64-pc-linux-gnu' '--host=x86_64-pc-linux-gnu' '--mandir=/usr/share/man' '--infodir=/usr/share/info' '--datadir=/usr/share' '--sysconfdir=/etc' '--localstatedir=/var/lib' '--docdir=/usr/share/doc/bind-9.16.11' '--htmldir=/usr/share/doc/bind-9.16.11/html' '--with-sysroot=/' '--libdir=/usr/lib64' 'AR=/usr/bin/x86_64-pc-linux-gnu-ar' '--prefix=/usr' '--sysconfdir=/etc/bind' '--localstatedir=/var' '--with-libtool' '--enable-full-report' '--without-readline' '--with-openssl=/usr' '--without-cmocka' '--enable-linux-caps' '--disable-dnsrps' '--disable-dnstap' '--disable-fixed-rrset' '--without-dlz-bdb' '--with-dlopen' '--with-dlz-filesystem' '--with-dlz-stub' '--without-gssapi' '--without-json-c' '--without-dlz-ldap' '--with-dlz-mysql' '--without-dlz-odbc' '--without-dlz-postgres' '--without-lmdb' '--without-libxml2' '--with-zlib' '--without-python' '--with-maxminddb' '--enable-geoip' 'build_alias=x86_64-pc-linux-gnu' 'host_alias=x86_64-pc-linux-gnu' 'CFLAGS=-march=znver1 -O3 -ggdb3 -pipe' 'LDFLAGS=-Wl,-O1 -Wl,--as-needed' compiled by GCC 9.3.0 compiled with OpenSSL version: OpenSSL 1.1.1j 16 Feb 2021 linked to OpenSSL version: OpenSSL 1.1.1j 16 Feb 2021 compiled with libuv version: 1.40.0 linked to libuv version: 1.40.0 compiled with zlib version: 1.2.11 linked to zlib version: 1.2.11 linked to maxminddb version: 1.5.0 threads support is enabled
default paths: named configuration: /etc/bind/named.conf rndc configuration: /etc/bind/rndc.conf DNSSEC root key: /etc/bind/bind.keys nsupdate session key: /var/run/named/session.key named PID file: /var/run/named/named.pid named lock file: /var/run/named/named.lock geoip-directory: /usr/share/GeoIP
Steps to reproduce
- install BIND 9.16.11 with DLZ support
- install mariadb 10.5.8
- install DLZ converted spam domain list (view attachment)
- install DLZ connector
What is the current bug behavior?
Bind crashes with segfaults, when using file instead of dlz, everything is OK.
What is the expected correct behavior?
Bind loads zones + runs correctly
Relevant configuration files
DLZ connector:
dlz "null_dlz" {
database "mysql
{host=127.0.0.1 port=3306 dbname=dlz_null ssl=false user=named pass=named}
{select '$zone$' AS zone from dns_records where zone = 'null' OR zone = '$zone$' LIMIT 1}
{select ttl, type, mx_priority, case when lower(type)='txt' then concat('\"', data, '\"')
else data end from dns_records where (zone = 'null' OR zone = '$zone$') and (host = '*' OR host = '$record$') AND NOT (type = 'SOA' or type='NS')}
{select ttl, type, mx_priority, data, resp_person, serial, refresh, retry, expire, minimum
from dns_records where (zone = 'null' OR zone = '$zone$') AND (type = 'SOA' or type='NS')}
{select ttl, type, host, mx_priority, data, resp_person, serial, refresh, retry, expire,
minimum from dns_records where (zone = 'null' OR zone = '$zone$') and NOT (type = 'SOA' or type = 'NS')}
{select '$zone$' AS zone from xfr_table where (zone = 'null' OR zone = '$zone$') and client = '$client$'}
{update data_count set count = count + 1 where (zone ='null' OR zone = '$zone$') AND client = '$client$'}";
search no;
};
include "blacklist.inc.dlz"
SQL database dump:
Enter password:
-- MariaDB dump 10.18 Distrib 10.5.8-MariaDB, for Linux (x86_64)
--
-- Host: localhost Database: dlz_null
-- ------------------------------------------------------
-- Server version 10.5.8-MariaDB-log
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
--
-- Table structure for table `data_count`
--
DROP TABLE IF EXISTS `data_count`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `data_count` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`count` bigint(20) unsigned NOT NULL DEFAULT 0,
`zone` varchar(255) DEFAULT 'null',
`client` varchar(255) NOT NULL DEFAULT '',
PRIMARY KEY (`id`),
KEY `zone` (`zone`)
) ENGINE=Aria AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 PAGE_CHECKSUM=1;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `data_count`
--
LOCK TABLES `data_count` WRITE;
/*!40000 ALTER TABLE `data_count` DISABLE KEYS */;
INSERT INTO `data_count` VALUES (1,0,'null','');
/*!40000 ALTER TABLE `data_count` ENABLE KEYS */;
UNLOCK TABLES;
--
-- Table structure for table `dns_records`
--
DROP TABLE IF EXISTS `dns_records`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `dns_records` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`zone` varchar(255) NOT NULL,
`host` varchar(255) NOT NULL DEFAULT '@',
`type` varchar(255) NOT NULL,
`data` text DEFAULT NULL,
`ttl` int(11) NOT NULL DEFAULT 86400,
`mx_priority` int(11) DEFAULT NULL,
`refresh` int(11) DEFAULT NULL,
`retry` int(11) DEFAULT NULL,
`expire` int(11) DEFAULT NULL,
`minimum` int(11) DEFAULT NULL,
`serial` bigint(20) DEFAULT NULL,
`resp_person` varchar(255) DEFAULT NULL,
`primary_ns` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `type` (`type`),
KEY `host` (`host`),
KEY `zone` (`zone`),
KEY `zone_host_index` (`zone`(30),`host`(30)),
KEY `type_index` (`type`(8))
) ENGINE=Aria AUTO_INCREMENT=6 DEFAULT CHARSET=utf8 PAGE_CHECKSUM=1;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `dns_records`
--
LOCK TABLES `dns_records` WRITE;
/*!40000 ALTER TABLE `dns_records` DISABLE KEYS */;
INSERT INTO `dns_records` VALUES (1,'null','@','SOA',NULL,180,NULL,10800,7200,604800,86400,2011091101,'localhost.','admin.localhost.'),(2,'null','@','NS','localhost',180,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL),(3,'null','@','A','0.0.0.0',180,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL),(4,'null','*','A','0.0.0.0',180,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL),(5,'null','*','AAAA','::',180,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL);
/*!40000 ALTER TABLE `dns_records` ENABLE KEYS */;
UNLOCK TABLES;
--
-- Table structure for table `xfr_table`
--
DROP TABLE IF EXISTS `xfr_table`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `xfr_table` (
`zone` varchar(255) NOT NULL,
`client` varchar(255) NOT NULL,
KEY `zone` (`zone`),
KEY `client` (`client`),
KEY `zone_client_index` (`zone`(30),`client`(30))
) ENGINE=Aria DEFAULT CHARSET=utf8 PAGE_CHECKSUM=1;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `xfr_table`
--
LOCK TABLES `xfr_table` WRITE;
/*!40000 ALTER TABLE `xfr_table` DISABLE KEYS */;
INSERT INTO `xfr_table` VALUES ('null','*');
/*!40000 ALTER TABLE `xfr_table` ENABLE KEYS */;
UNLOCK TABLES;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
-- Dump completed on 2021-02-25 10:21:58
GDB backtrace:
(gdb) setargs -d 1 -u named -n 1 -g -c /etc/named/named2.conf
(gdb) run
... -- truncated
Query String: select 'paczkonnat.app' AS zone from dns_records where zone = 'null' OR zone = 'paczkonnat.app' LIMIT 1
Thread 3 "isc-worker0000" received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7ffff6211640 (LWP 20149)]
0x00007ffff7116746 in strlen () from /lib64/libc.so.6
(gdb) bt
#0 0x00007ffff7116746 in strlen () from /lib64/libc.so.6
#1 0x00005555555ab3bd in sdlzh_build_querystring (mctx=mctx@entry=0x5555555eb090, querylist=0x7fffd6acd210) at ../../contrib/dlz/drivers/sdlz_helper.c:287
#2 0x00005555555ac8ac in mysql_get_resultset (zone=<optimized out>, record=<optimized out>, client=<optimized out>, query=5, dbdata=0x7fffd6adfd68, rs=0x0) at ../../contrib/dlz/drivers/dlz_mysql_driver.c:276
#3 0x00005555555ad5f7 in mysql_findzone (driverarg=<optimized out>, methods=<optimized out>, clientinfo=<optimized out>, name=0x7ffff6210740 "paczkonnat.app", dbdata=0x7fffd6adfd68) at ../../contrib/dlz/drivers/dlz_mysql_driver.c:508
#4 mysql_findzone (driverarg=<optimized out>, dbdata=0x7fffd6adfd68, name=0x7ffff6210740 "paczkonnat.app", methods=<optimized out>, clientinfo=<optimized out>) at ../../contrib/dlz/drivers/dlz_mysql_driver.c:478
#5 0x00007ffff7e70cc6 in dns_sdlzfindzone (driverarg=0x7ffff6b552e0, dbdata=0x7fffd6adfd68, mctx=0x5555555eb090, rdclass=<optimized out>, name=0x7fffde822720, methods=0x0, clientinfo=0x0, dbp=0x7ffff6210bd8) at sdlz.c:1681
#6 0x00007ffff7ed2c84 in zone_load (zone=0x7fffde8225e0, flags=<optimized out>, locked=locked@entry=true) at zone.c:2159
#7 0x00007ffff7ed3141 in zone_asyncload (task=0x7ffff091f220, event=<optimized out>) at zone.c:2303
#8 0x00007ffff7c91150 in dispatch (threadid=<optimized out>, manager=0x7ffff6b60010) at task.c:1152
#9 run (queuep=<optimized out>) at task.c:1344
#10 0x00007ffff7574fde in start_thread () from /lib64/libpthread.so.0
#11 0x00007ffff717973f in clone () from /lib64/libc.so.6
(gdb)