[SERVER-10425] Do not sign-extend characters passed to isspace() Created: 03/Aug/13  Updated: 11/Jul/16  Resolved: 05/Aug/13

Status: Closed
Project: Core Server
Component/s: Internal Code
Affects Version/s: None
Fix Version/s: 2.5.2

Type: Bug Priority: Major - P3
Reporter: Tad Marshall Assignee: Tad Marshall
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Backwards Compatibility: Fully Compatible
Operating System: ALL
Participants:

 Description   

The Windows debug build has some runtime tests (in the debug version of the MSVC "C" runtime library) that other builds don't have. test.exe prints some errors in its debug build that indicate code problems.

http://buildlogs.mongodb.org/Windows%2064-bit%20DEBUG/builds/928/test/core/test.exe

Sat Aug 03 11:16:52.043 [testsuite] going to run suite: json
// ... snip ...
Sat Aug 03 11:16:52.152 [testsuite] 	 going to run test: class JsonTests::FromJsonTests::UnquotedFieldNameBad18
Sat Aug 03 11:16:52.152 [testsuite] *** C runtime error: f:\dd\vctools\crt_bld\self_64_amd64\crt\src\isctype.c(56) : Assertion failed: (unsigned)(c + 1) <= 256
Sat Aug 03 11:16:53.010 [testsuite] test.exe  ...\src\mongo\util\stacktrace.cpp(169)                               mongo::printStackTrace+0x5b
Sat Aug 03 11:16:53.010 [testsuite] test.exe  ...\src\mongo\util\stacktrace.cpp(284)                               mongo::crtDebugCallback+0x137
Sat Aug 03 11:16:53.010 [testsuite] test.exe  f:\dd\vctools\crt_bld\self_64_amd64\crt\src\dbgrptt.c(605)           _VCrtDbgReportW+0x812
Sat Aug 03 11:16:53.010 [testsuite] test.exe  f:\dd\vctools\crt_bld\self_64_amd64\crt\src\dbgrpt.c(242)            _CrtDbgReportWV+0x43
Sat Aug 03 11:16:53.026 [testsuite] test.exe  f:\dd\vctools\crt_bld\self_64_amd64\crt\src\dbgrpt.c(258)            _CrtDbgReportW+0x4d
Sat Aug 03 11:16:53.026 [testsuite] test.exe  f:\dd\vctools\crt_bld\self_64_amd64\crt\src\isctype.c(56)            _chvalidator+0x3f
Sat Aug 03 11:16:53.026 [testsuite] test.exe  f:\dd\vctools\crt_bld\self_64_amd64\crt\src\_ctype.c(188)            isspace+0x1f
Sat Aug 03 11:16:53.026 [testsuite] test.exe  ...\src\mongo\db\json.cpp(912)                                       mongo::JParse::accept+0x64
Sat Aug 03 11:16:53.026 [testsuite] test.exe  ...\src\mongo\db\json.cpp(172)                                       mongo::JParse::object+0xe1
Sat Aug 03 11:16:53.026 [testsuite] test.exe  ...\src\mongo\db\json.cpp(981)                                       mongo::fromjson+0x105
Sat Aug 03 11:16:53.026 [testsuite] test.exe  ...\src\mongo\db\json.cpp(992)                                       mongo::fromjson+0x45
Sat Aug 03 11:16:53.026 [testsuite] test.exe  ...\src\mongo\dbtests\jsontests.cpp(458)                             JsonTests::FromJsonTests::Bad::run+0xa7
Sat Aug 03 11:16:53.026 [testsuite] test.exe  ...\src\mongo\unittest\unittest.h(296)                               mongo::unittest::Suite::runTestObject<JsonTests::FromJsonTests::UnquotedFieldNameBad18>+0x33
Sat Aug 03 11:16:53.026 [testsuite] test.exe  ...\src\third_party\boost\boost\function\function_template.hpp(113)  boost::detail::function::void_function_invoker0<void (__cdecl*)(void),void>::invoke+0x2f
Sat Aug 03 11:16:53.026 [testsuite] test.exe  ...\src\third_party\boost\boost\function\function_template.hpp(761)  boost::function0<void>::operator()+0x87
Sat Aug 03 11:16:53.026 [testsuite] test.exe  ...\src\mongo\unittest\unittest.h(194)                               mongo::unittest::TestHolder::run+0x2f
Sat Aug 03 11:16:53.026 [testsuite] test.exe  ...\src\mongo\unittest\unittest.cpp(164)                             mongo::unittest::Suite::run+0x74b
Sat Aug 03 11:16:53.026 [testsuite] test.exe  ...\src\mongo\unittest\unittest.cpp(228)                             mongo::unittest::Suite::run+0x498
Sat Aug 03 11:16:53.026 [testsuite] test.exe  ...\src\mongo\dbtests\framework.cpp(270)                             mongo::dbtests::runDbTests+0x1328
Sat Aug 03 11:16:53.026 [testsuite] test.exe  ...\src\mongo\dbtests\dbtests.cpp(41)                                dbtestsMain+0x170

Since isspace() takes an int, we need to prevent sign-extension of chars that have the high bit set.

src/mongo/db/json.cpp lines 906 to 914:

    bool JParse::accept(const char* token, bool advance) {
        MONGO_JSON_DEBUG("token: " << token);
        const char* check = _input;
        if (token == NULL) {
            return false;
        }
        while (check < _input_end && isspace(*check)) {
            ++check;
        }

The same problem exists elsewhere in this file:

Sat Aug 03 11:16:57.378 [testsuite] *** C runtime error: f:\dd\vctools\crt_bld\self_64_amd64\crt\src\isctype.c(56) : Assertion failed: (unsigned)(c + 1) <= 256
Sat Aug 03 11:16:58.252 [testsuite] test.exe  ...\src\mongo\util\stacktrace.cpp(169)                               mongo::printStackTrace+0x5b
Sat Aug 03 11:16:58.252 [testsuite] test.exe  ...\src\mongo\util\stacktrace.cpp(284)                               mongo::crtDebugCallback+0x137
Sat Aug 03 11:16:58.252 [testsuite] test.exe  f:\dd\vctools\crt_bld\self_64_amd64\crt\src\dbgrptt.c(605)           _VCrtDbgReportW+0x812
Sat Aug 03 11:16:58.252 [testsuite] test.exe  f:\dd\vctools\crt_bld\self_64_amd64\crt\src\dbgrpt.c(242)            _CrtDbgReportWV+0x43
Sat Aug 03 11:16:58.252 [testsuite] test.exe  f:\dd\vctools\crt_bld\self_64_amd64\crt\src\dbgrpt.c(258)            _CrtDbgReportW+0x4d
Sat Aug 03 11:16:58.252 [testsuite] test.exe  f:\dd\vctools\crt_bld\self_64_amd64\crt\src\isctype.c(56)            _chvalidator+0x3f
Sat Aug 03 11:16:58.252 [testsuite] test.exe  f:\dd\vctools\crt_bld\self_64_amd64\crt\src\_ctype.c(188)            isspace+0x1f
Sat Aug 03 11:16:58.252 [testsuite] test.exe  ...\src\mongo\db\json.cpp(770)                                       mongo::JParse::field+0xbe
Sat Aug 03 11:16:58.252 [testsuite] test.exe  ...\src\mongo\db\json.cpp(183)                                       mongo::JParse::object+0x1b6
Sat Aug 03 11:16:58.252 [testsuite] test.exe  ...\src\mongo\db\json.cpp(981)                                       mongo::fromjson+0x105
Sat Aug 03 11:16:58.252 [testsuite] test.exe  ...\src\mongo\db\json.cpp(992)                                       mongo::fromjson+0x45
Sat Aug 03 11:16:58.252 [testsuite] test.exe  ...\src\mongo\dbtests\jsontests.cpp(458)                             JsonTests::FromJsonTests::Bad::run+0xa7
Sat Aug 03 11:16:58.252 [testsuite] test.exe  ...\src\mongo\unittest\unittest.h(296)                               mongo::unittest::Suite::runTestObject<JsonTests::FromJsonTests::UnquotedFieldNameBad18>+0x33
Sat Aug 03 11:16:58.252 [testsuite] test.exe  ...\src\third_party\boost\boost\function\function_template.hpp(113)  boost::detail::function::void_function_invoker0<void (__cdecl*)(void),void>::invoke+0x2f
Sat Aug 03 11:16:58.252 [testsuite] test.exe  ...\src\third_party\boost\boost\function\function_template.hpp(761)  boost::function0<void>::operator()+0x87
Sat Aug 03 11:16:58.252 [testsuite] test.exe  ...\src\mongo\unittest\unittest.h(194)                               mongo::unittest::TestHolder::run+0x2f
Sat Aug 03 11:16:58.252 [testsuite] test.exe  ...\src\mongo\unittest\unittest.cpp(164)                             mongo::unittest::Suite::run+0x74b
Sat Aug 03 11:16:58.252 [testsuite] test.exe  ...\src\mongo\unittest\unittest.cpp(228)                             mongo::unittest::Suite::run+0x498
Sat Aug 03 11:16:58.252 [testsuite] test.exe  ...\src\mongo\dbtests\framework.cpp(270)                             mongo::dbtests::runDbTests+0x1328
Sat Aug 03 11:16:58.252 [testsuite] test.exe  ...\src\mongo\dbtests\dbtests.cpp(41)                                dbtestsMain+0x170

src/mongo/db/json.cpp lines 761 to 770:

    Status JParse::field(std::string* result) {
        MONGO_JSON_DEBUG("");
        if (accept(DOUBLEQUOTE, false) || accept(SINGLEQUOTE, false)) {
            // Quoted key
            // TODO: make sure quoted field names cannot contain null characters
            return quotedString(result);
        }
        else {
            // Unquoted key
            while (_input < _input_end && isspace(*_input)) ++_input;



 Comments   
Comment by auto [ 05/Aug/13 ]

Author:

{u'username': u'tadmarshall', u'name': u'Tad Marshall', u'email': u'tad@10gen.com'}

Message: SERVER-10425 Do not sign-extend characters passed to isspace()
Branch: master
https://github.com/mongodb/mongo/commit/00eeec1ab83c8f4921d1bc1352221168a3a01900

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