qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Carlo Marcelo Arenas Belon <carenas@sajinet.com.pe>
To: Alexander Graf <agraf@suse.de>
Cc: qemu-devel@nongnu.org, Paul Brook <paul@codesourcery.com>
Subject: Re: [Qemu-devel] [PATCH] Fix ATAPI GET_CONFIGURATION function
Date: Sun, 25 May 2008 05:38:38 -0500	[thread overview]
Message-ID: <20080525103837.GA16584@tapir> (raw)
In-Reply-To: <3D336F70-E1E2-410A-BA62-ED3F6295DD09@suse.de>

[-- Attachment #1: Type: text/plain, Size: 753 bytes --]

Alexander

sorry if I wasn't clear enough.  I wasn't arguing about your patch (which is
correct) but was trying to explain why the old implementation was done the way
it was, in an (obviously excessive) effort to prevent a buffer overflow for the
response (which used to be hardcoded to 32 bytes regardless of the size of the
buffer) as shown by :

  http://svn.savannah.gnu.org/viewvc/trunk/hw/ide.c?root=qemu&r1=3147&r2=3161

a slightly modified version of your patch (which I'd been using against kvm 
and validated correct with Linux and Solaris guests) attached.

the only difference, is that it handles explicitly the empty buffer case and
cleans up the len calculation which shouldn't had been calculated
conditionally as you pointed out.

Carlo

[-- Attachment #2: kvm-69-qemu-ide-dvdrom.patch --]
[-- Type: text/plain, Size: 3610 bytes --]

--- kvm-69/qemu/hw/ide.c        2008-05-12 04:30:43.000000000 -0700
+++ kvm-69/qemu/hw/ide.c        2008-05-25 01:44:27.000000000 -0700
@@ -1716,6 +1716,7 @@
     case GPCMD_GET_CONFIGURATION:
         {
             uint32_t len;
+            uint8_t index = 0;
 
             /* only feature 0 is supported */
             if (packet[2] != 0 || packet[3] != 0) {
@@ -1726,41 +1727,40 @@
 
             /* XXX: could result in alignment problems in some architectures */
             max_len = ube16_to_cpu(packet + 7);
-            /*
-             * XXX: avoid overflow for io_buffer if max_len is bigger than the
-             *      size of that buffer (dimensioned to max number of sectors
-             *      to transfer at once)
-             *
-             *      Only a problem if the feature/profiles grow exponentially.
-             */
-            if (max_len > 512) /* XXX: assume 1 sector */
-                max_len = 512;
-
-            memset(buf, 0, max_len);
-            /* 
-             * the number of sectors from the media tells us which profile
-             * to use as current.  0 means there is no media
-             *
-             * XXX: fails to detect correctly DVDs with less data burned
-             *      than what a CD can hold
-             */
-            if ((s -> nb_sectors)) {
-                if ((s -> nb_sectors > CD_MAX_SECTORS))
-                    cpu_to_ube16(buf + 6, MMC_PROFILE_DVD_ROM);
-                else
-                    cpu_to_ube16(buf + 6, MMC_PROFILE_CD_ROM);
-            }
 
-            len = 8; /* header completed */
-            if (max_len > len) {
-                uint8_t index = 0;
-
-                buf[10] = 0x02 | 0x01; /* persistent and current */
-                len += 4; /* header */
-                len += ide_atapi_set_profile(buf, &index, MMC_PROFILE_DVD_ROM);
-                len += ide_atapi_set_profile(buf, &index, MMC_PROFILE_CD_ROM);
-            }
-            cpu_to_ube32(buf, len - 4); /* data length */
+            if (max_len > 0) {
+                /*
+                 * XXX: avoid overflow for io_buffer if max_len is bigger than
+                 *      the size of that buffer (dimensioned to max number of
+                 *      sectors to transfer at once)
+                 *
+                 *      Only a problem if the feature/profiles grow 
+                 */
+                if (max_len > 512) /* XXX: assume 1 sector */
+                    max_len = 512;
+
+                memset(buf, 0, max_len);
+                /* 
+                 * the number of sectors from the media tells us which profile
+                 * to use as current.  0 means there is no media
+                 *
+                 * XXX: fails to detect correctly DVDs with less data burned
+                 *      than what a CD can hold
+                 */
+                if (s -> nb_sectors) {
+                    if (s -> nb_sectors > CD_MAX_SECTORS)
+                        cpu_to_ube16(buf + 6, MMC_PROFILE_DVD_ROM);
+                    else
+                        cpu_to_ube16(buf + 6, MMC_PROFILE_CD_ROM);
+                }
+
+                buf[10] = 0x02 | 0x01; /* persistent and current */
+                len = 12; /* headers: 8 + 4 */
+                len += ide_atapi_set_profile(buf, &index, MMC_PROFILE_DVD_ROM);
+                len += ide_atapi_set_profile(buf, &index, MMC_PROFILE_CD_ROM);
+                cpu_to_ube32(buf, len - 4); /* data length */
+            } else
+                len = 0;
 
             ide_atapi_cmd_reply(s, len, max_len);
             break;

  reply	other threads:[~2008-05-25 10:17 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-05-21 14:34 [Qemu-devel] [PATCH] Fix ATAPI GET_CONFIGURATION function Alexander Graf
2008-05-24 10:31 ` Alexander Graf
2008-05-24 19:54   ` Alexander Graf
2008-05-25  7:53   ` Carlo Marcelo Arenas Belon
2008-05-25  9:27     ` Alexander Graf
2008-05-25 10:38       ` Carlo Marcelo Arenas Belon [this message]
2008-05-26  8:59         ` Alexander Graf
2008-05-26 17:46         ` Alexander Graf
2008-05-27 18:10           ` Carlo Marcelo Arenas Belon
2008-05-30  1:32             ` Alexander Graf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20080525103837.GA16584@tapir \
    --to=carenas@sajinet.com.pe \
    --cc=agraf@suse.de \
    --cc=paul@codesourcery.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).