• Nicolai Stange's avatar
    lib/mpi: mpi_read_from_buffer(): return -EINVAL upon too short buffer · 7af791e0
    Nicolai Stange authored
    Currently, if the input buffer is shorter than the expected length as
    indicated by its first two bytes, an MPI instance of this expected length
    will be allocated and filled with as much data as is available. The rest
    will remain uninitialized.
    
    Instead of leaving this condition undetected, an error code should be
    reported to the caller.
    
    Since this situation indicates that the input buffer's first two bytes,
    encoding the number of expected bits, are garbled, -EINVAL is appropriate
    here.
    
    If the input buffer is shorter than indicated by its first two bytes,
    make mpi_read_from_buffer() return -EINVAL.
    Get rid of the 'nread' variable: with the new semantics, the total number
    of bytes read from the input buffer is known in advance.
    Signed-off-by: default avatarNicolai Stange <nicstange@gmail.com>
    Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
    7af791e0
mpicoder.c 9.25 KB