]> git.baikalelectronics.ru Git - kernel.git/commit
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)
commit29a1e0a76ea949393d8154fd6b0ccfab4f49ee3f
tree4ac6e6a42d23bbabe2d59dbd6cfd4678b226e12a
parent65ca98afa99bba909030c8498bb1eb4e1e0f4755
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