Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-7036

long log lines are logged with added NULs when truncated

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • 2.2.2, 2.3.0
    • Affects Version/s: 2.2.0
    • Component/s: Logging
    • Fully Compatible
    • ALL

      The code that logs the beginning and end of lines longer than 10 KB inserts two NULs into the log.

      At lines 339 and 342 in src/mongo/util/log.cpp in Logstream::flush(), the calls to b.appendStr() should include a 'false' second argument to prevent the addition of unwanted NUL characters.

      This code:

      if ( msg.size() > MAX_LOG_LINE ) {
          stringstream sss;
          sss << "warning: log line attempted (" << msg.size() / 1024 << "k) over max size(" << MAX_LOG_LINE / 1024 << "k)";
          sss << ", printing beginning and end ... ";
          b.appendStr( sss.str() );
          const char * xx = msg.c_str();
          b.appendBuf( xx , MAX_LOG_LINE / 3 );
          b.appendStr( " .......... " );
          b.appendStr( xx + msg.size() - ( MAX_LOG_LINE / 3 ) );
      }
      else {
          b.appendStr( msg );
      }
      

      should be

      if ( msg.size() > MAX_LOG_LINE ) {
          stringstream sss;
          sss << "warning: log line attempted (" << msg.size() / 1024 << "k) over max size(" << MAX_LOG_LINE / 1024 << "k)";
          sss << ", printing beginning and end ... ";
          b.appendStr( sss.str(), false );
          const char * xx = msg.c_str();
          b.appendBuf( xx , MAX_LOG_LINE / 3 );
          b.appendStr( " .......... ", false );
          b.appendStr( xx + msg.size() - ( MAX_LOG_LINE / 3 ) );
      }
      else {
          b.appendStr( msg );
      }
      

            Assignee:
            tad Tad Marshall
            Reporter:
            tad Tad Marshall
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: