All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Benoît Thébaudeau" <benoit.thebaudeau@advansee.com>
To: Takashi Iwai <tiwai@suse.de>
Cc: alsa-devel@alsa-project.org, Clemens Ladisch <clemens@ladisch.de>
Subject: Re: [PATCH] alsa-lib/tlv: fix handling of raw value	ranges
Date: Tue, 22 May 2012 04:19:12 +0200 (CEST)	[thread overview]
Message-ID: <1291060194.1061081.1337653152624.JavaMail.root@advansee.com> (raw)
In-Reply-To: <s5hipfp8225.wl%tiwai@suse.de>

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

Takashi Iwai wrote:
> Yes, the patch looks good to me.
> But I couldn't apply it because the mail is encoded in
> quoted-printable.  Could you fix it, or if it's difficult, give an
> attachment?

Sorry about that. I can't avoid that with my current mailer, so I attach the
patch. Tell me if it's OK for you like this.

Regards,
Benoît

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: improve-tlv-raw-val-robustness.patch --]
[-- Type: text/x-patch; name=improve-tlv-raw-val-robustness.patch, Size: 3160 bytes --]

alsa-lib/tlv: improve robustness of raw value ranges

snd_tlv_convert_from_dB() relies on rangemin/max blindly. Since this function is
exported, it is better for robustness and consistency to parse the range
properly, which this patch does.

Signed-off-by: Benoît Thébaudeau <benoit.thebaudeau@advansee.com>

--- alsa-lib/src/control/tlv.c
+++ alsa-lib/src/control/tlv.c
@@ -291,41 +291,37 @@ int snd_tlv_convert_from_dB(unsigned int
 {
         switch (tlv[0]) {
         case SND_CTL_TLVT_DB_RANGE: {
-                long dbmin, dbmax, prev_rangemax;
+                long dbmin, dbmax, prev_submax;
                 unsigned int pos, len;
                 len = int_index(tlv[1]);
-                if (len > MAX_TLV_RANGE_SIZE)
-                        return -EINVAL;
-                if (snd_tlv_get_dB_range(tlv, rangemin, rangemax,
-                                         &dbmin, &dbmax))
+                if (len < 6 || len > MAX_TLV_RANGE_SIZE)
                         return -EINVAL;
-                if (db_gain <= dbmin) {
-                        *value = rangemin;
-                        return 0;
-                } else if (db_gain >= dbmax) {
-                        *value = rangemax;
-                        return 0;
-                }
                 pos = 2;
-                prev_rangemax = 0;
+                prev_submax = 0;
                 while (pos + 4 <= len) {
-                        rangemin = (int)tlv[pos];
-                        rangemax = (int)tlv[pos + 1];
+                        long submin, submax;
+                        submin = (int)tlv[pos];
+                        submax = (int)tlv[pos + 1];
+                        if (rangemax < submax)
+                                submax = rangemax;
                         if (!snd_tlv_get_dB_range(tlv + pos + 2,
-                                                  rangemin, rangemax,
+                                                  submin, submax,
                                                   &dbmin, &dbmax) &&
                             db_gain >= dbmin && db_gain <= dbmax)
                                 return snd_tlv_convert_from_dB(tlv + pos + 2,
-                                                               rangemin, rangemax,
+                                                               submin, submax,
                                                                db_gain, value, xdir);
                         else if (db_gain < dbmin) {
-                                *value = xdir ? rangemin : prev_rangemax;
+                                *value = xdir || pos == 2 ? submin : prev_submax;
                                 return 0;
                         }
-                        prev_rangemax = rangemax;
+                        prev_submax = submax;
+                        if (rangemax == submax)
+                                break;
                         pos += int_index(tlv[pos + 3]) + 4;
                 }
-                return -EINVAL;
+                *value = prev_submax;
+                return 0;
         }
         case SND_CTL_TLVT_DB_SCALE: {
                 int min, step, max;

[-- Attachment #3: Type: text/plain, Size: 0 bytes --]



  reply	other threads:[~2012-05-22  2:15 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <a995c693-9d0b-4572-af9c-85e3deebf37c@zose-store-12>
2012-03-29 23:05 ` [PATCH] alsa-lib/tlv: fix handling of raw value ranges Benoît Thébaudeau
2012-03-30  8:37   ` Clemens Ladisch
2012-03-30 10:41     ` Benoît Thébaudeau
2012-03-30 11:44       ` Takashi Iwai
2012-03-30 11:51         ` Takashi Iwai
2012-03-30 13:07           ` Benoît Thébaudeau
2012-03-30 13:23             ` Takashi Iwai
2012-03-30 12:38       ` Clemens Ladisch
2012-03-30 13:07         ` Benoît Thébaudeau
2012-03-30 13:10           ` Benoît Thébaudeau
2012-03-30 13:51           ` Clemens Ladisch
2012-03-30 13:58             ` Benoît Thébaudeau
2012-03-30 15:20               ` Benoît Thébaudeau
2012-03-30 15:45                 ` Takashi Iwai
2012-03-30 15:59                   ` Benoît Thébaudeau
2012-03-30 15:44               ` Takashi Iwai
2012-03-30 16:15                 ` Benoît Thébaudeau
2012-05-21 19:38                 ` Benoît Thébaudeau
2012-05-22  0:57                   ` Takashi Iwai
2012-05-22  2:19                     ` Benoît Thébaudeau [this message]
2012-05-22  8:45                       ` Takashi Iwai
2012-05-22 16:06                         ` Benoît Thébaudeau
2012-05-22 23:54                           ` Takashi Iwai
2012-06-02  8:09       ` James Courtier-Dutton
2012-06-02 12:26         ` Benoît Thébaudeau

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=1291060194.1061081.1337653152624.JavaMail.root@advansee.com \
    --to=benoit.thebaudeau@advansee.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=clemens@ladisch.de \
    --cc=tiwai@suse.de \
    /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 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.