[SERVER-7036] long log lines are logged with added NULs when truncated Created: 13/Sep/12  Updated: 11/Jul/16  Resolved: 21/Sep/12

Status: Closed
Project: Core Server
Component/s: Logging
Affects Version/s: 2.2.0
Fix Version/s: 2.2.2, 2.3.0

Type: Bug Priority: Minor - P4
Reporter: Tad Marshall Assignee: Tad Marshall
Resolution: Done Votes: 0
Labels: neweng
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Backwards Compatibility: Fully Compatible
Operating System: ALL
Participants:

 Description   

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 );
}



 Comments   
Comment by auto [ 06/Nov/12 ]

Author:

{u'date': u'2012-09-21T17:55:18Z', u'email': u'tad@10gen.com', u'name': u'Tad Marshall'}

Message: SERVER-7036 do not insert NULs in abbreviated long logged lines

Pass 'false' for includeEndingNull in two calls to BufBuilder::appendStr
to we don't insert null terminators in the middle of an output buffer.
Branch: v2.2
https://github.com/mongodb/mongo/commit/a2af35fefe30de3aa64e7214968969beabce3239

Comment by auto [ 21/Sep/12 ]

Author:

{u'date': u'2012-09-21T10:55:18-07:00', u'name': u'Tad Marshall', u'email': u'tad@10gen.com'}

Message: SERVER-7036 do not insert NULs in abbreviated long logged lines

Pass 'false' for includeEndingNull in two calls to BufBuilder::appendStr
to we don't insert null terminators in the middle of an output buffer.
Branch: master
https://github.com/mongodb/mongo/commit/6df07abe328e69666b4ae732d8e38b5880a989bf

Generated at Thu Feb 08 03:13:27 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.