[Mapguide-trac] [mapguide-trac] #2901: Security sweep

MapGuide Open Source trac_mapguide at osgeo.org
Fri Nov 13 03:09:13 PST 2026


#2901: Security sweep
----------------------+----------------------
 Reporter:  jng       |        Owner:  jng
     Type:  task      |       Status:  closed
 Priority:  high      |    Milestone:  4.0.1
Component:  General   |      Version:
 Severity:  critical  |   Resolution:  fixed
 Keywords:            |  External ID:
----------------------+----------------------
Changes (by jng):

 * resolution:   => fixed
 * status:  assigned => closed

Comment:

 In [changeset:"10288" 10288]:
 {{{#!CommitTicketReference repository="" revision="10288"
 #2901: Fix the buffer overflows and input-validation gaps a security sweep
 found

 A read-through of Common, Server, Web and Portable (no Oem, no third party
 code) found eleven
 defects - two critical, three high, four medium, two low - and a pattern
 behind most of them:
 sprintf into a fixed stack buffer, where the size of the destination and
 the length of the result
 were two unrelated facts maintained by hand at every call site.

 Make that pattern impossible to write at those call sites.
 MgUtil::FormatBuffer is a variadic
 template over char (&)[N]: the buffer's size is deduced from the argument,
 so a call cannot pass a
 size that is not the buffer's own and cannot be given a pointer at all,
 and it formats with
 vsnprintf, truncating and always NUL-terminating, returning the length the
 format would have
 produced. It carries __attribute__((format(printf, 2, 3))) on GCC and
 Clang, so -Wformat now checks
 every call. That check is not decoration: it is what found four further
 mismatches that were
 already there, listed below.

 98 call sites in 26 files were rewritten: 62 to MgUtil::FormatBuffer, 28
 to snprintf in the
 libraries that do not link Foundation (Common/MdfParser/IOUtil.cpp and the
 MG renderers
 DWFRenderer, KmlRenderer and ObservationMesh), and the two %lf tolerance
 fields in
 SpatialContextData to MgUtil::DoubleToString, where a 128-byte buffer
 could not hold the value
 being described in the first place.

 The findings:

 - External entity and DTD resolution was on for every document the server
 parses, so a map or
   symbol definition could make the server read a local file or fetch a URL
 on its behalf.
   setLoadExternalDTD(false) and setDisableDefaultEntityResolution(true)
 are now set by
   Common/Foundation/System/XmlUtil.cpp, Common/MdfParser/SAX2Parser.cpp,
   Common/MdfParser/FSDSAX2Parser.cpp and
 Portable/MgPortable/Services/ResourceService.cpp.
 - Common/Renderers/AGGImageIO.cpp sized two stack allocations from the
 image width and height and
   allocated them before checking anything. The row-pointer table and the
 per-row RGB buffer are
   `height` pointers and `width` pixels, so both are now bounded by
 MG_MAX_PNG_DIMENSION (65536,
   512 KB and 192 KB respectively) and checked before either allocation.
 - Three services turned a client- or definition-supplied number into a
 size without asking whether
   it could be one. Server/src/Services/Kml/ServerKmlService.cpp rejects a
 DPI that is zero,
   negative, not finite or above 10000 (ValidateDpi), and GetScale rejects
 a viewport of zero area.
   Server/src/Services/Tile/ServerTileService.cpp rejects a metatile factor
 outside the range the
   providers' fixed arrays can express (ValidateMetaTileFactor), and
 TileCacheDefaultProvider.cpp
   and TileCacheXYZProvider.cpp clamp the loop bound they iterate to.
 Server/src/Services/Rendering/
   ServerRenderingService.cpp applies the same check to both entry points
 that take the metatile
   factor the client sends.
 - Common/Foundation/Data/Byte.cpp copied numRead bytes without relating
 numRead to the length left
   in the destination; the copy, the position and the remaining length are
 now checked together.
 - The multipart request parser in
 Web/src/MapAgentCommon/MapAgentCommon.cpp scanned for the end of
   a part without bounding the scan to the request, and compared the end
 tag with a length that was
   not the tag's; the scan is bounded and the comparison is a memcmp.
 Web/src/IsapiAgent/
   IsapiPostParser.cpp allocated its buffer with room for a terminator but
 only wrote one on some
   content-type paths, leaving the multipart parser to run past the request
 as a C string; it is now
   terminated for every content type.
 - Server/src/Common/Manager/LogManager.cpp took the two names RenameLog
 works with as file names
   inside the log directory and passed them to it unfiltered, so either
 could name a path elsewhere;
   a separator in either is rejected.
 - The PHP, ASP.NET and JSP viewers passed a help page name from the query
 string straight to the
   filesystem. Web/src/mapviewerphp/{common,gettingstarted}.php,
   Web/src/mapviewernet/{common,gettingstarted}.aspx and
   Web/src/mapviewerjava/{common,gettingstarted}.jsp now validate the name
 against a page-name
   pattern and confirm the resolved path stays inside the localized help
 directory.

 What the format attribute found, all of it pre-existing:

 - Web/src/ApacheAgent/ApacheResponseHandler.cpp and
 Web/src/IsapiAgent/IsapiResponseHandler.cpp
   formatted a size_t Content-Length with %d, so the header reported the
 low 32 bits; the three
   sites now cast to INT32 like the outLen handling beside them.
 - Common/PlatformBase/Data/Int32Property.cpp read an INT32 with "%li" on
 the Linux branch, which
   reads eight bytes from a four-byte argument; it is "%d" now.
 - Common/Foundation/System/Util.cpp formatted an INT64 with "%lli", which
 is a long on LP64; it is
   "%lld" after a (long long) cast.

 Two further defects the tests turned up rather than the review:

 - MgUtil::TrimEndingZeros (both overloads) treated an integer string as if
 it had a fractional part
   and dropped its last digit: "100" came back as "1". Both now only trim
 when there is a '.'.
 - MgUtil::SingleToString and DoubleToString are used for the identity
 properties' string form in
   Common/PlatformBase/MapLayer/SelectionBase.cpp instead of a fixed-buffer
 %f, which both truncates
   and is locale dependent - an identity value is compared and stored, so
 it must be neither.

 Tests:

 - Server/src/UnitTesting/TestMisc.cpp: FormatBuffer (bounds, truncation,
 terminator),
   ByteReadBounds, XmlExternalEntityRejected, IntegerToStringBounds,
 FloatingPointToStringBounds and
   StringToNumberBounds, the last three covering every MgUtil conversion at
 its boundaries
   (INT32/INT64 limits, the 2^53 integer precision limit of the double
 path, denormals, 1e308, and
   the TrimEndingZeros cases above).
 - Server/src/UnitTesting/TestLogManager.cpp: three RenameLog traversal
 assertions.
 - Server/src/UnitTesting/TestKmlService.cpp and TestTileService.cpp:
 GetLayerKmlRejectsInvalidDpi
   and InvalidMetaTileFactorRejected.
 - Server/src/UnitTesting/TestServerAdminService.cpp: GetDocument read a
 document only a later case
   creates, so it passed or failed by order; it now writes the document,
 reads it back and checks
   the content.
 - Server/src/UnitTesting/TestRenderingService.cpp:
 RenderAreaSymbolClipping asserted on the pixels
   of a symbol <Text> primitive, which the renderer drops entirely when the
 font engine resolves no
   font, so the case failed for a reason unrelated to clipping on a machine
 with no configured font
   directory. Its second primitive is a <Path> now.

 Verified in both configurations against this change set: Debug (ASan/LSan)
 `mgserver test all`
 passes 658 cases / 49,777 assertions with no leak records and no
 AddressSanitizer summary, and
 Release `mgserver test all` passes 659 cases / 49,782 assertions. The
 three suites carrying the new
 cases (Misc, LogManager, KmlService, TileService, ServerAdminService,
 RenderingService) were also
 run one process each, which is where exit-time races differ from the
 aggregate.

 Fixes #2901
 }}}
-- 
Ticket URL: <https://trac.osgeo.org/mapguide/ticket/2901#comment:1>
MapGuide Open Source <http://mapguide.osgeo.org/>
MapGuide Open Source Internals


More information about the mapguide-trac mailing list