centos 7
integer weakness #19

2

Weakness Breakdown


Definition:

An integer overflow occurs when the answer to an arithmetic operation exceeds the maximum size of the integer type used to store it. The resulting value will appear to have wrapped around the maximum value and started again at the minimum value. This would look like a clock that represents 13:00 by pointing at 1:00. An attacker can use an integer overflow during a buffer length calculation, which results in the allocated buffer being too small to hold the data copied into it, thus causing a buffer overflow.

Warning code(s):

Unless checked, the resulting number can exceed the expected range.

File Name:

python-dmidecode-3.12.2/src/xmlpythonizer.c

Context:

The highlighted line of code below is the trigger point of this particular Centos 7 integer weakness.

 
        // Loop through it's children
        foreach_xmlnode(map_n, ptr_n) {
                ptzTYPES type_key, type_value;
                char *key = NULL, *value = NULL;
                char *rootpath = NULL;
                char *listidx = NULL;
                int fixedsize = 0;
                if( ptr_n->type != XML_ELEMENT_NODE ) {
                        continue;
                }

                // Get the attributes defining key, keytype, value and valuetype
                key = dmixml_GetAttrValue(ptr_n, "key");
                type_key = _convert_maptype(logp, dmixml_GetAttrValue(ptr_n, "keytype"));

                value = dmixml_GetAttrValue(ptr_n, "value");
                type_value = _convert_maptype(logp, dmixml_GetAttrValue(ptr_n, "valuetype"));

                rootpath = dmixml_GetAttrValue(ptr_n, "rootpath");

                listidx = dmixml_GetAttrValue(ptr_n, "index_attr");
                if( listidx != NULL ) {
                        char *fsz = dmixml_GetAttrValue(ptr_n, "fixedsize");
                        fixedsize = (fsz != NULL ? atoi(fsz) : 0);
                }

                if( (type_value == ptzDICT) || (type_value == ptzLIST_DICT) ) {
                        // When value type is ptzDICT, traverse the children nodes
                        // - should contain another Map set instead of a value attribute
                        if( ptr_n->children == NULL ) {
                                continue;
                        }
                        // Recursion
                        retmap = ptzmap_Add(retmap, rootpath, type_key, key, type_value,
                                            (type_value == ptzLIST_DICT ? value : NULL),
                                            _do_dmimap_parsing_typeid(logp, ptr_n->children->next));
                } else {
                        char *tmpstr = NULL;

                        // Append the value as a normal value when the
                        // value type is not a Python Dict
                        retmap = ptzmap_Add(retmap, rootpath, type_key, key, type_value, value, NULL);

                        // Set emptyIsNone flag
                        if( (tmpstr = dmixml_GetAttrValue(ptr_n, "emptyIsNone")) != NULL ) {
                                switch( retmap->type_value ) {
                                case ptzSTR:
                                case ptzINT:
                                case ptzFLOAT: 

The registered trademark Linux® is used pursuant to a sublicense from the Linux Foundation, the exclusive licensee of Linus Torvalds, owner of the mark on a world­wide basis.