diff mbox

rawmidi: virtual: fix reading into a small buffer

Message ID b91aca79-8808-0cc4-ff3b-ad7ea16dec4b@ladisch.de (mailing list archive)
State New, archived
Headers show

Commit Message

Clemens Ladisch March 18, 2017, 10:10 p.m. UTC
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>

Comments

Takashi Sakamoto March 19, 2017, 6:23 a.m. UTC | #1
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
Takashi Iwai March 20, 2017, 9:35 a.m. UTC | #2
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
>
diff mbox

Patch

--- 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;
 		}