Log4cxx
  1. Log4cxx
  2. LOGCXX-191

Application cores when syslog appender is given an unreachable host/ip.

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Critical Critical
    • Resolution: Fixed
    • Affects Version/s: 0.10.0
    • Fix Version/s: 0.10.0
    • Component/s: Configurator
    • Labels:
      None

      Description

      When a syslog appender is set up with a host/ip that is unreachable, the application cores.

      The fault appears to lie in inetaddress.cpp, line #84, which does a strlen() call on a variable that is assumed to be set. The return code of the prior call to apr_getnameinfo() is not checked for success.

        Activity

        Hide
        Curt Arnold added a comment -

        Addressed core in syslogwriter when address is unreachable in rev 577560.

        Show
        Curt Arnold added a comment - Addressed core in syslogwriter when address is unreachable in rev 577560.
        Hide
        Curt Arnold added a comment -

        Committed a different fix in rev 577550. The problem appears to only occur when the address is resolvable, but the IP address does not respond with a host name.

        I added a test/src/java directory which contains JUnit tests that provide an equivalent test of the Java Runtime implementation.

        I did not change the SyslogWriter messages as they are equivalent to the log4j messages under the same conditions. Neither message is ideal since neither all logging or all syslogging will fail under those conditions, just a particular appender will fail.

        Show
        Curt Arnold added a comment - Committed a different fix in rev 577550. The problem appears to only occur when the address is resolvable, but the IP address does not respond with a host name. I added a test/src/java directory which contains JUnit tests that provide an equivalent test of the Java Runtime implementation. I did not change the SyslogWriter messages as they are equivalent to the log4j messages under the same conditions. Neither message is ideal since neither all logging or all syslogging will fail under those conditions, just a particular appender will fail.
        Hide
        Myles Bunbury added a comment -

        The following patch seems to resolve this problem satisfactorily:

        Index: src/main/cpp/inetaddress.cpp
        ===================================================================
        — src/main/cpp/inetaddress.cpp (revision 572744)
        +++ src/main/cpp/inetaddress.cpp (working copy)
        @@ -72,21 +72,47 @@
        apr_sockaddr_t *currentAddr = address;
        while(currentAddr != NULL) {
        // retrieve the IP address of this InetAddress.

        • LogString ipAddrString;
          char *ipAddr;
        • apr_sockaddr_ip_get(&ipAddr, currentAddr);
        • Transcoder::decode(ipAddr, strlen(ipAddr), ipAddrString);
          + apr_status_t nRetVal = apr_sockaddr_ip_get(&ipAddr, currentAddr);
          +
          + if (APR_SUCCESS == nRetVal)
          Unknown macro: {+ LogString ipAddrString;+ Transcoder}

          else

          { + /* + Ignore this address. - result.push_back(new InetAddress(hostNameString, ipAddrString)); + Don't throw an exception here since there may be other currentAddr elements that are OK. + If we can't add at least one to the result list by the end of the loop, we'll + throw an error after we're done looping. + */ + }

          +
          currentAddr = currentAddr->next;
          }

        + if (result.size() == 0)

        { + LogString msg(LOG4CXX_STR("Can't get information about host: ")); + msg.append(host); + LogLog::error(msg); + std::string s; + Transcoder::encode(msg, s); + throw UnknownHostException(s); + }

        +
        return result;
        }

        Index: src/main/cpp/syslogwriter.cpp
        ===================================================================
        — src/main/cpp/syslogwriter.cpp (revision 572744)
        +++ src/main/cpp/syslogwriter.cpp (working copy)
        @@ -39,7 +39,7 @@
        catch(UnknownHostException& e)

        { LogLog::error(((LogString) LOG4CXX_STR("Could not find ")) + syslogHost1 + - LOG4CXX_STR(". All logging will FAIL."), e); + LOG4CXX_STR(". All syslog logging will FAIL."), e); }

        try
        @@ -49,18 +49,18 @@
        catch (SocketException& e)

        { LogLog::error(((LogString) LOG4CXX_STR("Could not instantiate DatagramSocket to ")) + syslogHost1 + - LOG4CXX_STR(". All logging will FAIL."), e); + LOG4CXX_STR(". All syslog logging will FAIL."), e); }

        }

        void SyslogWriter::write(const LogString& source) {

        • LOG4CXX_ENCODE_CHAR(data, source);
          + if(this->ds != 0 && this->address != 0) {
          + LOG4CXX_ENCODE_CHAR(data, source);
        • DatagramPacketPtr packet =
          + DatagramPacketPtr packet =
          new DatagramPacket((void*) data.c_str(), data.length() + 1,
          address, SYSLOG_PORT);
        • if(this->ds != 0) { ds->send(packet); }

          }

        Show
        Myles Bunbury added a comment - The following patch seems to resolve this problem satisfactorily: Index: src/main/cpp/inetaddress.cpp =================================================================== — src/main/cpp/inetaddress.cpp (revision 572744) +++ src/main/cpp/inetaddress.cpp (working copy) @@ -72,21 +72,47 @@ apr_sockaddr_t *currentAddr = address; while(currentAddr != NULL) { // retrieve the IP address of this InetAddress. LogString ipAddrString; char *ipAddr; apr_sockaddr_ip_get(&ipAddr, currentAddr); Transcoder::decode(ipAddr, strlen(ipAddr), ipAddrString); + apr_status_t nRetVal = apr_sockaddr_ip_get(&ipAddr, currentAddr); + + if (APR_SUCCESS == nRetVal) Unknown macro: {+ LogString ipAddrString;+ Transcoder} else { + /* + Ignore this address. - result.push_back(new InetAddress(hostNameString, ipAddrString)); + Don't throw an exception here since there may be other currentAddr elements that are OK. + If we can't add at least one to the result list by the end of the loop, we'll + throw an error after we're done looping. + */ + } + currentAddr = currentAddr->next; } + if (result.size() == 0) { + LogString msg(LOG4CXX_STR("Can't get information about host: ")); + msg.append(host); + LogLog::error(msg); + std::string s; + Transcoder::encode(msg, s); + throw UnknownHostException(s); + } + return result; } Index: src/main/cpp/syslogwriter.cpp =================================================================== — src/main/cpp/syslogwriter.cpp (revision 572744) +++ src/main/cpp/syslogwriter.cpp (working copy) @@ -39,7 +39,7 @@ catch(UnknownHostException& e) { LogLog::error(((LogString) LOG4CXX_STR("Could not find ")) + syslogHost1 + - LOG4CXX_STR(". All logging will FAIL."), e); + LOG4CXX_STR(". All syslog logging will FAIL."), e); } try @@ -49,18 +49,18 @@ catch (SocketException& e) { LogLog::error(((LogString) LOG4CXX_STR("Could not instantiate DatagramSocket to ")) + syslogHost1 + - LOG4CXX_STR(". All logging will FAIL."), e); + LOG4CXX_STR(". All syslog logging will FAIL."), e); } } void SyslogWriter::write(const LogString& source) { LOG4CXX_ENCODE_CHAR(data, source); + if(this->ds != 0 && this->address != 0) { + LOG4CXX_ENCODE_CHAR(data, source); DatagramPacketPtr packet = + DatagramPacketPtr packet = new DatagramPacket((void*) data.c_str(), data.length() + 1, address, SYSLOG_PORT); if(this->ds != 0) { ds->send(packet); } }
        Hide
        Myles Bunbury added a comment -

        The following is a stack trace take from a core file generated by this problem:

        #8 0x003c0353 in strlen () from /lib/libc.so.6
        #9 0x082140f6 in log4cxx::helpers::InetAddress::getAllByName
        (host=@0xb6f7ace0)
        at /home/jake/logging-log4cxx/src/main/cpp/inetaddress.cpp:84
        #10 0x08214281 in log4cxx::helpers::InetAddress::getByName
        (host=@0xb6f7ace0)
        at /home/jake/logging-log4cxx/src/main/cpp/inetaddress.cpp:97
        #11 0x08269c1c in SyslogWriter (this=0xb6402db0,
        syslogHost1=@0xb6f7ace0)
        at /home/jake/logging-log4cxx/src/main/cpp/syslogwriter.cpp:37
        #12 0x0824314e in log4cxx::net::SyslogAppender::setSyslogHost
        (this=0xb64031c8, syslogHost1=@0xb6f7ace0)
        at /home/jake/logging-log4cxx/src/main/cpp/syslogappender.cpp:331
        #13 0x08244219 in log4cxx::net::SyslogAppender::setOption
        (this=0xb64031c8, option=@0xb6f7ace4, value=@0xb6f7ace0)
        at /home/jake/logging-log4cxx/src/main/cpp/syslogappender.cpp:305
        #14 0x081d1a9c in log4cxx::config::PropertySetter::setProperty
        (this=0xb6f7ad30, option=@0xb6f7ace4, value=@0xb6f7ace0)
        at /home/jake/logging-log4cxx/src/main/cpp/propertysetter.cpp:93
        #15 0x081d1cb3 in log4cxx::config::PropertySetter::setProperties
        (this=0xb6f7ad30, properties=@0xb6f7b028, prefix=@0xb6f7adfc,
        p=@0xb6f7ad84)
        at /home/jake/logging-log4cxx/src/main/cpp/propertysetter.cpp:76
        #16 0x081d1dd9 in log4cxx::config::PropertySetter::setProperties
        (obj=@0xb6f7ae00, properties=@0xb6f7b028, prefix=@0xb6f7adfc,
        p=@0xb6f7ad84)
        at /home/jake/logging-log4cxx/src/main/cpp/propertysetter.cpp:43
        #17 0x081c68c6 in log4cxx::PropertyConfigurator::parseAppender
        (this=0xb6f7b094, props=@0xb6f7b028, appenderName=@0xb6f7ae70)

        at /home/jake/logging-log4cxx/src/main/cpp/propertyconfigurator.cpp:419
        #18 0x081c760f in log4cxx::PropertyConfigurator::parseCategory
        (this=0xb6f7b094, props=@0xb6f7b028, logger=@0xb6f7af40,
        loggerName=@0xb6f7af48, value=@0xb6f7af44)

        at /home/jake/logging-log4cxx/src/main/cpp/propertyconfigurator.cpp:355
        #19 0x081c801a in log4cxx::PropertyConfigurator::parseCatsAndRenderers
        (this=0xb6f7b094, props=@0xb6f7b028, hierarchy=@0x916c58c)

        at /home/jake/logging-log4cxx/src/main/cpp/propertyconfigurator.cpp:252
        #20 0x081c8d62 in log4cxx::PropertyConfigurator::doConfigure
        (this=0xb6f7b094, properties=@0xb6f7b028, hierarchy=@0x916c58c)

        at /home/jake/logging-log4cxx/src/main/cpp/propertyconfigurator.cpp:159
        #21 0x081c8fee in log4cxx::PropertyConfigurator::doConfigure
        (this=0xb6f7b094, configFileName=@0xb6f7b0f4, hierarchy=@0x916c58c)

        at /home/jake/logging-log4cxx/src/main/cpp/propertyconfigurator.cpp:98
        #22 0x081c949d in log4cxx::PropertyConfigurator::configure
        (configFilename=@0xb6f7b0f4)
        at /home/jake/logging-log4cxx/src/main/cpp/propertyconfigurator.cpp:107
        #23 0x081a5ee6 in ReloadLogConfiguration
        (sCfgPathAndFileName=@0xb6f7b274) at Logging/LogConfiguration.cpp:27
        #24 0x081a509b in CheckForLogConfigurationChanges
        (pLogCfgMonitorData=0x8437554) at Logging/LogCfgFileMonitor.cpp:75
        #25 0x08179934 in Thread_Start (arg=0x91837a0) at
        Thread/THREAD_Utils.cpp:65
        #26 0x00dd62db in start_thread () from /lib/libpthread.so.0
        #27 0x0042114e in clone () from /lib/libc.so.6

        Show
        Myles Bunbury added a comment - The following is a stack trace take from a core file generated by this problem: #8 0x003c0353 in strlen () from /lib/libc.so.6 #9 0x082140f6 in log4cxx::helpers::InetAddress::getAllByName (host=@0xb6f7ace0) at /home/jake/logging-log4cxx/src/main/cpp/inetaddress.cpp:84 #10 0x08214281 in log4cxx::helpers::InetAddress::getByName (host=@0xb6f7ace0) at /home/jake/logging-log4cxx/src/main/cpp/inetaddress.cpp:97 #11 0x08269c1c in SyslogWriter (this=0xb6402db0, syslogHost1=@0xb6f7ace0) at /home/jake/logging-log4cxx/src/main/cpp/syslogwriter.cpp:37 #12 0x0824314e in log4cxx::net::SyslogAppender::setSyslogHost (this=0xb64031c8, syslogHost1=@0xb6f7ace0) at /home/jake/logging-log4cxx/src/main/cpp/syslogappender.cpp:331 #13 0x08244219 in log4cxx::net::SyslogAppender::setOption (this=0xb64031c8, option=@0xb6f7ace4, value=@0xb6f7ace0) at /home/jake/logging-log4cxx/src/main/cpp/syslogappender.cpp:305 #14 0x081d1a9c in log4cxx::config::PropertySetter::setProperty (this=0xb6f7ad30, option=@0xb6f7ace4, value=@0xb6f7ace0) at /home/jake/logging-log4cxx/src/main/cpp/propertysetter.cpp:93 #15 0x081d1cb3 in log4cxx::config::PropertySetter::setProperties (this=0xb6f7ad30, properties=@0xb6f7b028, prefix=@0xb6f7adfc, p=@0xb6f7ad84) at /home/jake/logging-log4cxx/src/main/cpp/propertysetter.cpp:76 #16 0x081d1dd9 in log4cxx::config::PropertySetter::setProperties (obj=@0xb6f7ae00, properties=@0xb6f7b028, prefix=@0xb6f7adfc, p=@0xb6f7ad84) at /home/jake/logging-log4cxx/src/main/cpp/propertysetter.cpp:43 #17 0x081c68c6 in log4cxx::PropertyConfigurator::parseAppender (this=0xb6f7b094, props=@0xb6f7b028, appenderName=@0xb6f7ae70) at /home/jake/logging-log4cxx/src/main/cpp/propertyconfigurator.cpp:419 #18 0x081c760f in log4cxx::PropertyConfigurator::parseCategory (this=0xb6f7b094, props=@0xb6f7b028, logger=@0xb6f7af40, loggerName=@0xb6f7af48, value=@0xb6f7af44) at /home/jake/logging-log4cxx/src/main/cpp/propertyconfigurator.cpp:355 #19 0x081c801a in log4cxx::PropertyConfigurator::parseCatsAndRenderers (this=0xb6f7b094, props=@0xb6f7b028, hierarchy=@0x916c58c) at /home/jake/logging-log4cxx/src/main/cpp/propertyconfigurator.cpp:252 #20 0x081c8d62 in log4cxx::PropertyConfigurator::doConfigure (this=0xb6f7b094, properties=@0xb6f7b028, hierarchy=@0x916c58c) at /home/jake/logging-log4cxx/src/main/cpp/propertyconfigurator.cpp:159 #21 0x081c8fee in log4cxx::PropertyConfigurator::doConfigure (this=0xb6f7b094, configFileName=@0xb6f7b0f4, hierarchy=@0x916c58c) at /home/jake/logging-log4cxx/src/main/cpp/propertyconfigurator.cpp:98 #22 0x081c949d in log4cxx::PropertyConfigurator::configure (configFilename=@0xb6f7b0f4) at /home/jake/logging-log4cxx/src/main/cpp/propertyconfigurator.cpp:107 #23 0x081a5ee6 in ReloadLogConfiguration (sCfgPathAndFileName=@0xb6f7b274) at Logging/LogConfiguration.cpp:27 #24 0x081a509b in CheckForLogConfigurationChanges (pLogCfgMonitorData=0x8437554) at Logging/LogCfgFileMonitor.cpp:75 #25 0x08179934 in Thread_Start (arg=0x91837a0) at Thread/THREAD_Utils.cpp:65 #26 0x00dd62db in start_thread () from /lib/libpthread.so.0 #27 0x0042114e in clone () from /lib/libc.so.6

          People

          • Assignee:
            Curt Arnold
            Reporter:
            Myles Bunbury
          • Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development