From patchwork Sat Mar 18 22:10:33 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Clemens Ladisch X-Patchwork-Id: 9632345 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 6611660132 for ; Sat, 18 Mar 2017 22:11:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4B2022832B for ; Sat, 18 Mar 2017 22:11:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3D00C2833C; Sat, 18 Mar 2017 22:11:03 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EA89D2832B for ; Sat, 18 Mar 2017 22:11:01 +0000 (UTC) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id 61A3B266B2C; Sat, 18 Mar 2017 23:10:56 +0100 (CET) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id 05471266B38; Sat, 18 Mar 2017 23:10:55 +0100 (CET) Received: from webclient5.webclient5.de (webclient5.webclient5.de [136.243.32.179]) by alsa0.perex.cz (Postfix) with ESMTP id 0D706266AF1 for ; Sat, 18 Mar 2017 23:10:52 +0100 (CET) Received: from [192.168.42.18] (tmo-123-0.customers.d1-online.com [80.187.123.0]) by webclient5.webclient5.de (Postfix) with ESMTPSA id 633FE5582081; Sat, 18 Mar 2017 23:10:51 +0100 (CET) To: Takashi Iwai , alsa-devel@alsa-project.org From: Clemens Ladisch Message-ID: Date: Sat, 18 Mar 2017 23:10:33 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.99.2 at webclient5 X-Virus-Status: Clean Subject: [alsa-devel] [PATCH] rawmidi: virtual: fix reading into a small buffer X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP In the special case for handling partial messages, the pointer calculations were wrong, which would result in data corruption. Signed-off-by: Clemens Ladisch --- 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; }