fedora 24
integer weakness #8

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:

CheMPS2-1.8/CheMPS2/Hamiltonian.cpp

Context:

The highlighted line of code below is the trigger point of this particular Fedora 24 integer weakness.

 
    struct stat file_info;
    const bool on_disk = (( fcidumpfile.length() > 0 ) && ( stat( fcidumpfile.c_str(), &file_info ) == 0 ));
    if ( on_disk == false ){
       cout << "CheMPS2::Hamiltonian : Unable to find FCIDUMP file " << fcidumpfile << "!" << endl;
    }
    assert( on_disk );

    cout << "CheMPS2::Hamiltonian : Reading FCIDUMP file " << fcidumpfile << endl;

    const int nIrreps = SymmInfo.getNumberOfIrreps();
    int * psi2molpro = new int[ nIrreps ];
    SymmInfo.symm_psi2molpro( psi2molpro );

    ifstream thefcidump( fcidumpfile.c_str() );
    string line, part;
    int pos, pos2;

    // Get the number of orbitals
    getline( thefcidump, line ); // &FCI NORB= X,NELEC= Y,MS2= Z,   
    pos  = line.find( "NORB" );
    pos  = line.find( "=", pos ); //1
    pos2 = line.find( ",", pos ); //4
    part = line.substr( pos+1, pos2-pos-1 );
    L = atoi( part.c_str() );
    if ( CheMPS2::HAMILTONIAN_debugPrint ){ cout << "The number of orbitals <<" << part << ">> or " << L << "." << endl; }

    // Get the orbital irreps in psi4 convention (XOR, see Irreps.h).
    orb2irrep = new int[ L ];
    getline( thefcidump, line ); //  ORBSYM=A,B,C,D,
    getline( thefcidump, part );
    while ( part.find( "ISYM" ) == string::npos ){
       pos = line.find("\n");
       if ( pos != string::npos ){ line.erase( pos ); }
       pos = part.find(" ");
       if ( pos != string::npos ){ part.erase( pos, 1 ); }
       line.append( part );
       getline( thefcidump, part );
    }
    pos = line.find( "ORBSYM" );
    pos = line.find( "=", pos ); //1
    for ( int orb = 0; orb < L; orb++ ){
        pos2 = line.find( ",", pos+1 ); //3
        part = line.substr( pos+1, pos2-pos-1 );
        const int molproirrep = atoi( part.c_str() );
        if ( CheMPS2::HAMILTONIAN_debugPrint ){ cout << "This molpro irrep <<" << part << ">> or " << molproirrep << "." << endl; }
        orb2irrep[ orb ] = -1;
        for ( int irrep = 0; irrep < nIrreps; irrep++ ){
            if ( molproirrep == psi2molpro[ irrep ] ){
                orb2irrep[ orb ] = irrep; 

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.