centos 7
integer weakness #17

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.

 
                // Prepare a data list
                value = PyList_New(0);

                // If we're working on a fixed list, create one which contains
                // only Py_None objects.  Otherwise the list will be filled with
                // <nil> elements.
                if( map_p->fixed_list_size > 0 ) {
                        for( i = 0; i < map_p->fixed_list_size; i++ ) {
                                PyList_Append(value, Py_None);
                        }
                }

                for( i = 0; i < xpo->nodesetval->nodeNr; i++ ) {
                        PyObject *dataset = NULL;

                        dataset = pythonizeXMLnode(logp, map_p->child, xpo->nodesetval->nodeTab[i]);
                        if( dataset != NULL ) {
                                // If we have a fixed list and we have a index value for the list
                                if( (map_p->fixed_list_size > 0) && (map_p->list_index != NULL) ) {
                                        char *idx = NULL;
                                        idx = dmixml_GetAttrValue(xpo->nodesetval->nodeTab[i],
                                                                  map_p->list_index);
                                        if( idx != NULL ) {
                                                PyList_SetItem(value, atoi(idx)-1, dataset);
                                        }
                                } else {
                                        // No list index - append the value
                                        PyList_Append(value, dataset);
                                }
                        } else {
                                // If NULL, something is wrong - exception is already set.
                                return NULL;
                        }
                }
                PyADD_DICT_VALUE(retdata, key, value);
                xmlXPathFreeObject(xpo);
                break;

        default:
                log_append(logp, LOGFL_NODUPS, LOG_WARNING, "Unknown value type: %i", map_p->type_value);
                break;
        }

        free(key);
        xmlXPathFreeContext(xpctx);
        xmlFreeDoc(xpdoc);
        return retdata;
}
 

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.