From: Stephan Mueller Date: Sun, 18 Oct 2015 10:45:18 +0000 (+0200) Subject: lib/mpi: fix off by one in mpi_read_raw_from_sgl X-Git-Tag: KARO-TX6UL-2015-11-03~86^2~36 X-Git-Url: https://git.kernelconcepts.de/?p=karo-tx-linux.git;a=commitdiff_plain;h=63349d02c195030f97c9c2000bbf32539056316f lib/mpi: fix off by one in mpi_read_raw_from_sgl The patch fixes the analysis of the input data which contains an off by one. The issue is visible when the SGL contains one byte per SG entry. The code for checking for zero bytes does not operate on the data byte. Signed-off-by: Stephan Mueller Signed-off-by: Herbert Xu --- diff --git a/lib/mpi/mpicoder.c b/lib/mpi/mpicoder.c index c20ef27ad876..c7e0a705eecf 100644 --- a/lib/mpi/mpicoder.c +++ b/lib/mpi/mpicoder.c @@ -446,8 +446,11 @@ MPI mpi_read_raw_from_sgl(struct scatterlist *sgl, unsigned int len) const u8 *buff = sg_virt(sg); int len = sg->length; - while (len-- && !*buff++) + while (len && !*buff) { lzeros++; + len--; + buff++; + } if (len && *buff) break;