All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] rawmidi: virtual: fix reading into a small buffer
@ 2017-03-18 22:10 Clemens Ladisch
  2017-03-19  6:23 ` Takashi Sakamoto
  2017-03-20  9:35 ` Takashi Iwai
  0 siblings, 2 replies; 3+ messages in thread
From: Clemens Ladisch @ 2017-03-18 22:10 UTC (permalink / raw)
  To: Takashi Iwai, alsa-devel

In the special case for handling partial messages, the pointer
calculations were wrong, which would result in data corruption.

Signed-off-by: Clemens Ladisch <clemens@ladisch.de>

--- alsa-lib/src/rawmidi/rawmidi_virt.c
+++ alsa-lib/src/rawmidi/rawmidi_virt.c
@@ -263,8 +263,8 @@ static ssize_t snd_rawmidi_virtual_read(snd_rawmidi_t *rmidi, void *buffer, size
 		}
 		size1 = virt->in_buf_size - virt->in_buf_ofs;
 		if ((size_t)size1 > size) {
-			virt->in_buf_ofs += size1 - size;
-			memcpy(buffer, virt->in_buf_ptr, size);
+			memcpy(buffer, virt->in_buf_ptr + virt->in_buf_ofs, size);
+			virt->in_buf_ofs += size;
 			result += size;
 			break;
 		}

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] rawmidi: virtual: fix reading into a small buffer
  2017-03-18 22:10 [PATCH] rawmidi: virtual: fix reading into a small buffer Clemens Ladisch
@ 2017-03-19  6:23 ` Takashi Sakamoto
  2017-03-20  9:35 ` Takashi Iwai
  1 sibling, 0 replies; 3+ messages in thread
From: Takashi Sakamoto @ 2017-03-19  6:23 UTC (permalink / raw)
  To: Clemens Ladisch, Takashi Iwai, alsa-devel

Hi,

On Mar 19 2017 07:10, Clemens Ladisch wrote:
> In the special case for handling partial messages, the pointer
> calculations were wrong, which would result in data corruption.
>
> Signed-off-by: Clemens Ladisch <clemens@ladisch.de>

Reviewd-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>

> --- alsa-lib/src/rawmidi/rawmidi_virt.c
> +++ alsa-lib/src/rawmidi/rawmidi_virt.c
> @@ -263,8 +263,8 @@ static ssize_t snd_rawmidi_virtual_read(snd_rawmidi_t *rmidi, void *buffer, size
>  		}
>  		size1 = virt->in_buf_size - virt->in_buf_ofs;
>  		if ((size_t)size1 > size) {
> -			virt->in_buf_ofs += size1 - size;
> -			memcpy(buffer, virt->in_buf_ptr, size);
> +			memcpy(buffer, virt->in_buf_ptr + virt->in_buf_ofs, size);
> +			virt->in_buf_ofs += size;
>  			result += size;
>  			break;
>  		}


Regards

Takashi Sakamoto

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] rawmidi: virtual: fix reading into a small buffer
  2017-03-18 22:10 [PATCH] rawmidi: virtual: fix reading into a small buffer Clemens Ladisch
  2017-03-19  6:23 ` Takashi Sakamoto
@ 2017-03-20  9:35 ` Takashi Iwai
  1 sibling, 0 replies; 3+ messages in thread
From: Takashi Iwai @ 2017-03-20  9:35 UTC (permalink / raw)
  To: Clemens Ladisch; +Cc: alsa-devel

On Sat, 18 Mar 2017 23:10:33 +0100,
Clemens Ladisch wrote:
> 
> In the special case for handling partial messages, the pointer
> calculations were wrong, which would result in data corruption.
> 
> Signed-off-by: Clemens Ladisch <clemens@ladisch.de>

Applied (with Sakamoto-san's review tag) now.  Thanks.


Takashi

> 
> --- alsa-lib/src/rawmidi/rawmidi_virt.c
> +++ alsa-lib/src/rawmidi/rawmidi_virt.c
> @@ -263,8 +263,8 @@ static ssize_t snd_rawmidi_virtual_read(snd_rawmidi_t *rmidi, void *buffer, size
>  		}
>  		size1 = virt->in_buf_size - virt->in_buf_ofs;
>  		if ((size_t)size1 > size) {
> -			virt->in_buf_ofs += size1 - size;
> -			memcpy(buffer, virt->in_buf_ptr, size);
> +			memcpy(buffer, virt->in_buf_ptr + virt->in_buf_ofs, size);
> +			virt->in_buf_ofs += size;
>  			result += size;
>  			break;
>  		}
> _______________________________________________
> Alsa-devel mailing list
> Alsa-devel@alsa-project.org
> http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-03-20  9:35 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-18 22:10 [PATCH] rawmidi: virtual: fix reading into a small buffer Clemens Ladisch
2017-03-19  6:23 ` Takashi Sakamoto
2017-03-20  9:35 ` Takashi Iwai

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.