[SERVER-8387] geoNear Command: better bounds checking for the num argument Created: 29/Jan/13  Updated: 11/Jul/16  Resolved: 07/Feb/13

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

Type: Improvement Priority: Major - P3
Reporter: Stephen Lee Assignee: hari.khalsa@10gen.com
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
Participants:

 Description   

When '{{num : { $in : [-1,NumberLong(-Infinity)] }}}', eg.

assert.throws( function() {
    t.runCommand('geoNear', {near: [50,50], num: -1})
}, {}, "num: -1" )

the following assertion is outputted

ue Jan 29 14:38:07.861 [conn2]  test.geo2 Assertion failure numWanted >= 0 src/mongo/db/geo/2d.cpp 2384
0x106c34a8b 0x106c0e91c 0x106993e3e 0x1069a7b10 0x10678d9a5 0x10678e8e3 0x10678f195 0x106a3160e 0x106a31e11 0x1069dec7f 0x10665cb02 0x106c2a579 0x106c67145 0x7fff92d78742 0x7fff92d65181 
 0   mongod                              0x0000000106c34a8b _ZN5mongo15printStackTraceERSo + 43
 1   mongod                              0x0000000106c0e91c _ZN5mongo12verifyFailedEPKcS1_j + 284
 2   mongod                              0x0000000106993e3e _ZN5mongo12run2DGeoNearERKNS_12IndexDetailsERNS_7BSONObjERSsRNS_14BSONObjBuilderE + 5518
 3   mongod                              0x00000001069a7b10 _ZN5mongo16Geo2dFindNearCmd3runERKSsRNS_7BSONObjEiRSsRNS_14BSONObjBuilderEb + 660
 4   mongod                              0x000000010678d9a5 _ZN5mongo12_execCommandEPNS_7CommandERKSsRNS_7BSONObjEiRSsRNS_14BSONObjBuilderEb + 37
 5   mongod                              0x000000010678e8e3 _ZN5mongo7Command11execCommandEPS0_RNS_6ClientEiPKcRNS_7BSONObjERNS_14BSONObjBuilderEb + 2523
 6   mongod                              0x000000010678f195 _ZN5mongo12_runCommandsEPKcRNS_7BSONObjERNS_11_BufBuilderINS_16TrivialAllocatorEEERNS_14BSONObjBuilderEbi + 1013
 7   mongod                              0x0000000106a3160e _ZN5mongo11runCommandsEPKcRNS_7BSONObjERNS_5CurOpERNS_11_BufBuilderINS_16TrivialAllocatorEEERNS_14BSONObjBuilderEbi + 46
 8   mongod                              0x0000000106a31e11 _ZN5mongo8runQueryERNS_7MessageERNS_12QueryMessageERNS_5CurOpES1_ + 1553
 9   mongod                              0x00000001069dec7f _ZN5mongo16assembleResponseERNS_7MessageERNS_10DbResponseERKNS_11HostAndPortE + 1519
 10  mongod                              0x000000010665cb02 _ZN5mongo16MyMessageHandler7processERNS_7MessageEPNS_21AbstractMessagingPortEPNS_9LastErrorE + 198
 11  mongod                              0x0000000106c2a579 _ZN5mongo17PortMessageServer17handleIncomingMsgEPv + 1657
 12  mongod                              0x0000000106c67145 thread_proxy + 229
 13  libsystem_c.dylib                   0x00007fff92d78742 _pthread_start + 327
 14  libsystem_c.dylib                   0x00007fff92d65181 thread_start + 13

but assert.throws() does not catch any exception.

ssert: did not throw exception: num: -1
Error: Printing Stack Trace
    at printStackTrace (src/mongo/shell/utils.js:37:7)
    at doassert (src/mongo/shell/utils.js:58:1)
    at Function.assert.throws (src/mongo/shell/utils.js:204:1)
    at /Users/slee/Source/mongodb-src-r2.3.2/jstests/geo2.js:54:8
Tue Jan 29 14:38:07.868 javascript execution failed src/mongo/shell/utils.js:59 did not throw exception: num: -1
throw msg;

Also, the assertion should probably refer to the "num" argument instead of the underlying variable, 'numWanted'.



 Comments   
Comment by auto [ 07/Feb/13 ]

Author:

{u'date': u'2013-01-30T20:40:55Z', u'email': u'hkhalsa@10gen.com', u'name': u'Hari Khalsa'}

Message: SERVER-8387 check numWanted in geoNear
Branch: master
https://github.com/mongodb/mongo/commit/4f5d0af7ed9ffd1f1d75a46ac3201643451b0bfb

Comment by Tad Marshall [ 29/Jan/13 ]

The error message is coming from a "verify" in the code, so the logged error message is quoting directly from the code; it is not an error message that we craft for the user.

The fix is what you noted: we need to validate user-provided arguments before they reach this code. The validation code can then throw a "user exception" with a user-friendly message.

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