Re: [CrystalSpace] #990: NULL pointer crash if library file doesn't contain <library> tag (fix included)

"CrystalSpace" <[email protected]> Sun, 21 Jul 2013 21:54:29 -0000
Newsgroups gmane.comp.graphics.crystalspace.tracker
Message-ID <[email protected]>
#990: NULL pointer crash if library file doesn't contain <library> tag (fix
included)
---------------------------+------------------------------------------------
 Reporter:  ralphcampbell  |       Owner:  admin
     Type:  defect         |      Status:  new  
 Priority:  major          |   Milestone:       
Component:  loader         |     Version:  V2.1 
 Keywords:                 |  
---------------------------+------------------------------------------------
Description changed by sunshine:

Old description:

> In a map file I added a <library>somefile</library> where the somefile
> didn't start with <library> and end with </library>.
> This resulted in a NULL pointer dereference.
> Another way to fix this would be to return an error but I found it useful
> to be able to include the file without having to change the contents
> since libraries can contain almost any other elements.
>
> {{{
> Index: plugins/csparser/csthreadedloader.cpp
> ===================================================================
> --- plugins/csparser/csthreadedloader.cpp       (revision 39501)
> +++ plugins/csparser/csthreadedloader.cpp       (working copy)
> @@ -1821,6 +1821,10 @@
>      {
>        // Do the quick pre-parse.
>        csRef<iDocumentNode> lib_node =
> doc->GetRoot()->GetNode("library");
> +      if (!lib_node)
> +      {
> +        lib_node = doc->GetRoot();
> +      }
> ParseAvailableObjects(dynamic_cast<csLoaderContext*>((iLoaderContext*)ldr_context),
> lib_node, *libs, *libIDs);
>
>        // Add info to arrays later.
> }}}

New description:

 In a map file I added a `<library>somefile</library>` where the
 ''somefile'' didn't start with `<library>` and end with `</library>`.
 This resulted in a NULL pointer dereference.
 Another way to fix this would be to return an error but I found it useful
 to be able to include the file without having to change the contents since
 libraries can contain almost any other elements.

 {{{
 #!diff
 Index: plugins/csparser/csthreadedloader.cpp
 ===================================================================
 --- plugins/csparser/csthreadedloader.cpp       (revision 39501)
 +++ plugins/csparser/csthreadedloader.cpp       (working copy)
 @@ -1821,6 +1821,10 @@
      {
        // Do the quick pre-parse.
        csRef<iDocumentNode> lib_node = doc->GetRoot()->GetNode("library");
 +      if (!lib_node)
 +      {
 +        lib_node = doc->GetRoot();
 +      }
 ParseAvailableObjects(dynamic_cast<csLoaderContext*>((iLoaderContext*)ldr_context),
 lib_node, *libs, *libIDs);

        // Add info to arrays later.
 }}}

--

-- 
Ticket URL: <http://www.crystalspace3d.org/trac/CS/ticket/990#comment:1>
CrystalSpace <http://www.crystalspace3d.org/>
Free open-source 3D SDK.
------------------------------------------------------------------------------
See everything from the browser to the database with AppDynamics
Get end-to-end visibility with application monitoring from AppDynamics
Isolate bottlenecks and diagnose root cause in seconds.
Start your free trial of AppDynamics Pro today!
http://pubads.g.doubleclick.net/gampad/clk?id=48808831&iu=/4140/ostg.clktrk