After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 705399 - Dereferenced after NULL check
Dereferenced after NULL check
Status: RESOLVED FIXED
Product: libxml2
Classification: Platform
Component: general
git master
Other Linux
: Normal critical
: ---
Assigned To: Daniel Veillard
libxml QA maintainers
Depends on:
Blocks:
 
 
Reported: 2013-08-03 11:45 UTC by Gaurav
Modified: 2013-08-04 15:32 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Gaurav 2013-08-03 11:45:40 UTC
In file:
https://git.gnome.org/browse/libxml2/tree/parserInternals.c

Function : xmlParserAddNodeInfo

At line : 1985
 if ((pos < ctxt->node_seq.length) &&
        (ctxt->node_seq.buffer != NULL) &&
        (ctxt->node_seq.buffer[pos].node == info->node)) {
        ctxt->node_seq.buffer[pos] = *info;
    }
In above if condition[ ctxt->node_seq.buffer != NULL ] means value ctxt->node_seq.buffer can be NULL. Take this if condition as false

Now at line : 1992
 In else condition
 
   else {
        if (ctxt->node_seq.length + 1 > ctxt->node_seq.maximum) {

            ---Some COde --
        }
take if condition is false.

Again at line: 2018
    if (pos != ctxt->node_seq.length) {
            unsigned long i;

            for (i = ctxt->node_seq.length; i > pos; i--)
                ctxt->node_seq.buffer[i] = ctxt->node_seq.buffer[i - 1];
        }

Taking if condition as true
   
   ctxt->node_seq.buffer is dereferenced. As, it is NUll so may lead to crash.
Comment 1 Daniel Veillard 2013-08-03 14:29:08 UTC
Actually if the buffer is NULL, then the maximum ought to be 0 and
the test line 1992 must be true in all cases, but to clarify the
situation and force the buffer allocation it is better to mate the
test explicit.
I commited ff76eb28c75451bc56e3b93f44dac155ca29e7f5 to git which should
get your static analysis tool to stop complaining :-)

Daniel
Comment 2 Gaurav 2013-08-04 15:32:28 UTC
Thanks for the clarification Daniel.