Fixes a nullptr deref under --check-config.
/* RemoteLogger */
g_lua.writeFunction("newRemoteLogger", [client](const std::string& remote, boost::optional<uint16_t> timeout, boost::optional<uint64_t> maxQueuedEntries, boost::optional<uint8_t> reconnectWaitTime) {
- if (client) {
- return std::shared_ptr<RemoteLoggerInterface>();
- }
- return std::shared_ptr<RemoteLoggerInterface>(new RemoteLogger(ComboAddress(remote), timeout ? *timeout : 2, maxQueuedEntries ? *maxQueuedEntries : 100, reconnectWaitTime ? *reconnectWaitTime : 1));
+ return std::shared_ptr<RemoteLoggerInterface>(new RemoteLogger(ComboAddress(remote), timeout ? *timeout : 2, maxQueuedEntries ? *maxQueuedEntries : 100, reconnectWaitTime ? *reconnectWaitTime : 1, client));
});
g_lua.writeFunction("newFrameStreamUnixLogger", [client](const std::string& address) {
- if (client) {
- return std::shared_ptr<RemoteLoggerInterface>();
- }
#ifdef HAVE_FSTRM
- return std::shared_ptr<RemoteLoggerInterface>(new FrameStreamLogger(AF_UNIX, address));
+ return std::shared_ptr<RemoteLoggerInterface>(new FrameStreamLogger(AF_UNIX, address, !client));
#else
throw std::runtime_error("fstrm support is required to build an AF_UNIX FrameStreamLogger");
#endif /* HAVE_FSTRM */
});
g_lua.writeFunction("newFrameStreamTcpLogger", [client](const std::string& address) {
- if (client) {
- return std::shared_ptr<RemoteLoggerInterface>();
- }
#if defined(HAVE_FSTRM) && defined(HAVE_FSTRM_TCP_WRITER_INIT)
- return std::shared_ptr<RemoteLoggerInterface>(new FrameStreamLogger(AF_INET, address));
+ return std::shared_ptr<RemoteLoggerInterface>(new FrameStreamLogger(AF_INET, address, !client));
#else
throw std::runtime_error("fstrm with TCP support is required to build an AF_INET FrameStreamLogger");
#endif /* HAVE_FSTRM */
#ifdef HAVE_FSTRM
-FrameStreamLogger::FrameStreamLogger(const int family, const std::string& address): d_family(family), d_address(address)
+FrameStreamLogger::FrameStreamLogger(const int family, const std::string& address, bool connect): d_family(family), d_address(address)
{
fstrm_res res;
throw std::runtime_error("FrameStreamLogger: fstrm_iothr_options_set_queue_model failed: " + std::to_string(res));
}
- d_iothr = fstrm_iothr_init(d_iothropt, &d_writer);
- if (!d_iothr) {
- throw std::runtime_error("FrameStreamLogger: fstrm_iothr_init() failed.");
- }
+ if (connect) {
+ d_iothr = fstrm_iothr_init(d_iothropt, &d_writer);
+ if (!d_iothr) {
+ throw std::runtime_error("FrameStreamLogger: fstrm_iothr_init() failed.");
+ }
- d_ioqueue = fstrm_iothr_get_input_queue(d_iothr);
- if (!d_ioqueue) {
- throw std::runtime_error("FrameStreamLogger: fstrm_iothr_get_input_queue() failed.");
+ d_ioqueue = fstrm_iothr_get_input_queue(d_iothr);
+ if (!d_ioqueue) {
+ throw std::runtime_error("FrameStreamLogger: fstrm_iothr_get_input_queue() failed.");
+ }
}
} catch (std::runtime_error &e) {
this->cleanup();
void FrameStreamLogger::queueData(const std::string& data)
{
+ if (!d_ioqueue || !d_iothr) {
+ return;
+ }
uint8_t *frame = (uint8_t*)malloc(data.length());
if (!frame) {
warnlog("FrameStreamLogger: cannot allocate memory for stream.");
class FrameStreamLogger : public RemoteLoggerInterface, boost::noncopyable
{
public:
- FrameStreamLogger(int family, const std::string& address);
+ FrameStreamLogger(int family, const std::string& address, bool connect);
virtual ~FrameStreamLogger();
virtual void queueData(const std::string& data) override;
virtual std::string toString() override
void RemoteLogger::worker()
{
- if (d_asyncConnect) {
- busyReconnectLoop();
- }
-
while(true) {
std::string data;
{
dnsdistcmd.extend(['--acl', acl])
print(' '.join(dnsdistcmd))
+ # validate config with --check-config, which sets client=true, possibly exposing bugs.
+ testcmd = dnsdistcmd + ['--check-config']
+ output = subprocess.check_output(testcmd, close_fds=True)
+ if output != b'Configuration \'dnsdist_test.conf\' OK!\n':
+ raise AssertionError('dnsdist --check-config failed: %s' % output)
+
if shutUp:
with open(os.devnull, 'w') as fdDevNull:
cls._dnsdist = subprocess.Popen(dnsdistcmd, close_fds=True, stdout=fdDevNull)