lib/mpi: mpi_read_from_buffer(): return -EINVAL upon too short buffer
authorNicolai Stange <nicstange@gmail.com>
Thu, 26 May 2016 21:19:53 +0000 (23:19 +0200)
committerHerbert Xu <herbert@gondor.apana.org.au>
Tue, 31 May 2016 08:42:00 +0000 (16:42 +0800)
commit7af791e0f0d00c14f01ba2ffe3b6e2b50a35fc6f
tree4ac6e6a42d23bbabe2d59dbd6cfd4678b226e12a
parentc5ce7c697c983693c441573d2948e0ab8d62726e
lib/mpi: mpi_read_from_buffer(): return -EINVAL upon too short buffer

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: Nicolai Stange <nicstange@gmail.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
lib/mpi/mpicoder.c
This page took 0.028619 seconds and 5 git commands to generate.