[Slirp] [PATCH] slirp: ncsi: compute checksum for valid data length
Philippe Mathieu-Daudé
philmd at redhat.com
Mon Dec 30 07:59:41 UTC 2019
Hi Prasad,
On 12/30/19 7:39 AM, P J P wrote:
> From: Prasad J Pandit <pjp at fedoraproject.org>
>
> 'ncsi_calculate_checksum' computes an optional checksum value for
> the ncsi response packet by reading the data as series of 2 byte
> words. But it receives the data length in no of bytes. Fix the for
I suppose by 'no' you mean 'number'.
> loop to run for half the iterations to compute checksum for valid
> data bytes and avoid OOB access.
>
> Reported-by: Xingwei Lin <linyi.lxw at antfin.com>
> Signed-off-by: Prasad J Pandit <pjp at fedoraproject.org>
> ---
> src/ncsi.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/src/ncsi.c b/src/ncsi.c
> index 6864b73..ddd980d 100644
> --- a/src/ncsi.c
> +++ b/src/ncsi.c
> @@ -47,7 +47,7 @@ static uint32_t ncsi_calculate_checksum(uint16_t *data, int len)
> * 32-bit unsigned sum of the NC-SI packet header and NC-SI packet
> * payload interpreted as a series of 16-bit unsigned integer values.
> */
> - for (i = 0; i < len; i++) {
> + for (i = 0; i < len / 2; i++) {
We could replace '2' by sizeof(data[0]) but since the type will never
change, 2 is easier.
> checksum += htons(data[i]);
> }
>
The libslirp README says [*] you can send patches to the list, but last
time I sent something the maintainers told me they prefer a GitLab merge
request, I didn't insisted and my patch got lost. But then if you open a
GitLab merge request the list isn't Cc'ed and patch aren't reviewed by
subscribers, so I dunno what's best.
Anyway:
Reviewed-by: Philippe Mathieu-Daudé <philmd at redhat.com>
[*] https://gitlab.freedesktop.org/slirp/libslirp
More information about the Slirp
mailing list