[SERVER-31375] pathExists on empty string prints stack trace Created: 03/Oct/17  Updated: 30/Oct/23  Resolved: 28/Nov/17

Status: Closed
Project: Core Server
Component/s: Shell
Affects Version/s: None
Fix Version/s: 3.7.1

Type: Bug Priority: Minor - P4
Reporter: Ian Boros Assignee: Fiona Rowan
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
Backwards Compatibility: Fully Compatible
Sprint: Platforms 2017-10-23, Platforms 2017-11-13, Platforms 2017-12-04
Participants:
Linked BF Score: 0

 Description   

To reproduce this, run inside a shell:

pathExists("");

The output is something like:

 mongo(_ZN5mongo15printStackTraceERNSt3__113basic_ostreamIcNS0_11char_traitsIcEEEE+0x3A) [0x101077f8a]
 mongo(_ZN5mongo10logContextEPKc+0x15F) [0x100ffee6f]
 mongo(_ZN5mongo12verifyFailedEPKcS1_j+0x230) [0x100fed9d0]
 mongo(_ZN5mongo11shell_utils10PathExistsERKNS_7BSONObjEPv+0x220) [0x100fda730]
 mongo(_ZN5mongo5mozjs18NativeFunctionInfo4callEP9JSContextN2JS8CallArgsE+0xC1) [0x100f8cce1]
 mongo(_ZN5mongo5mozjs7smUtils4callINS0_18NativeFunctionInfoEEEbP9JSContextjPN2JS5ValueE+0x36) [0x100f6fd56]
 mongo(_ZN2js6InvokeEP9JSContextRKN2JS8CallArgsENS_14MaybeConstructE+0x2D7) [0x10171d717]
 mongo(_ZL9InterpretP9JSContextRN2js8RunStateE+0xBE18) [0x1017167b8]
 mongo(_ZN2js9RunScriptEP9JSContextRNS_8RunStateE+0x1E9) [0x10170a949]
 mongo(_ZN2js13ExecuteKernelEP9JSContextN2JS6HandleIP8JSScriptEER8JSObjectRKNS2_5ValueENS_11ExecuteTypeENS_16AbstractFramePtrEPS9_+0x13B) [0x10171e10b]
 mongo(_ZN2js7ExecuteEP9JSContextN2JS6HandleIP8JSScriptEER8JSObjectPNS2_5ValueE+0xE8) [0x10171e298]
 mongo(_ZL13ExecuteScriptP9JSContextN2JS6HandleIP8JSObjectEENS2_IP8JSScriptEEPNS1_5ValueE+0x2B) [0x1015bb66b]
 mongo(_Z16JS_ExecuteScriptP9JSContextN2JS6HandleIP8JSScriptEENS1_13MutableHandleINS1_5ValueEEE+0x62) [0x1015bb602]
 mongo(_ZN5mongo5mozjs14MozJSImplScope4execENS_10StringDataERKNSt3__112basic_stringIcNS3_11char_traitsIcEENS3_9allocatorIcEEEEbbbi+0x1AF) [0x100f6d8ef]
 mongo(_ZNSt3__110__function6__funcIZN5mongo5mozjs15MozJSProxyScope4execENS2_10StringDataERKNS_12basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEEbbbiE4$_26NS9_ISE_EEFvvEEclEv+0x4F) [0x100f9f80f]
 mongo(_ZN5mongo5mozjs15MozJSProxyScope10implThreadEPv+0x1B9) [0x100f9b519]
 mongo(_ZN4nspr6Thread13ThreadRoutineEPv+0x1C) [0x100f50afc]
 mongo(_ZNSt3__114__thread_proxyINS_5tupleIJPFPvS2_EPN4nspr6ThreadEEEEEES2_S2_+0x61) [0x100f510e1]
 libsystem_pthread.dylib(_pthread_body+0xB4) [0x7fffe9be293b]
 libsystem_pthread.dylib(_pthread_body+0x0) [0x7fffe9be2887]
 libsystem_pthread.dylib(thread_start+0xD) [0x7fffe9be208d]
-----  END BACKTRACE  -----
2017-10-03T17:46:25.108-0400 E QUERY    [thread1] Error: assertion src/mongo/shell/shell_utils_launcher.cpp:808 

I think it'd be better to just return false in this case (unless if there's already specific reason not to).

Also, when the fuzzer produces a statement like this, the logs end up getting polluted with the resulting stack traces, which can make it more difficult to find stack information for "real bugs."



 Comments   
Comment by Githook User [ 28/Nov/17 ]

Author:

{'name': 'Fiona Rowan', 'username': 'fionaRowan', 'email': 'fiona.rowan@mongodb.com'}

Message: SERVER-31375: pathExists, resetDbpath, copyDbpath should not print stacktrace on empty string
Branch: master
https://github.com/mongodb/mongo/commit/1504678cecfc6d2746da740b0c71293c3b271911

Comment by Sara Golemon [ 13/Oct/17 ]

resetDbpath("");
copyDbpath("", "");
and probably several others have some over-aggressive verify(!thing.empth(); patterns. These should result in things like false return or a meaningful warning for things like copyDbpath().

src/mongo/shell/shell_utils_launcher.cpp

 819 BSONObj PathExists(const BSONObj& a, void* data) {
 820     verify(a.nFields() == 1);
 821     string path = a.firstElement().valuestrsafe();
 822     verify(!path.empty());
 823     bool exists = boost::filesystem::exists(path);
 824     return BSON(string("") << exists);
 825 }

Generated at Thu Feb 08 04:26:50 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.