qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: John Snow <jsnow@redhat.com>, qemu-block@nongnu.org
Cc: kwolf@redhat.com, qemu-devel@nongnu.org, mreitz@redhat.com
Subject: Re: [Qemu-devel] [Qemu-block] [PATCH 2/3] qemu-io: Check for trailing chars
Date: Mon, 26 Oct 2015 16:49:11 -0600	[thread overview]
Message-ID: <562EADE7.5070102@redhat.com> (raw)
In-Reply-To: <562EACCF.4060704@redhat.com>

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

On 10/26/2015 04:44 PM, Eric Blake wrote:
> On 10/26/2015 04:06 PM, John Snow wrote:
>> Make sure there's not trailing garbage, e.g.
>> "64k-whatever-i-want-here"
>>
>> Reported-by: Max Reitz <mreitz@redhat.com>
>> Signed-off-by: John Snow <jsnow@redhat.com>
>> ---
>>  qemu-io-cmds.c | 9 ++++++++-
>>  1 file changed, 8 insertions(+), 1 deletion(-)

>> +    ret = qemu_strtosz_suffix(s, &end, QEMU_STRTOSZ_DEFSUFFIX_B);
>> +    if (*end != '\0') {
>> +        /* Detritus at the end of the string */
>> +        return -EINVAL;
>> +    }
>> +    return ret;
>>  }
> 
> Eww.  This mixes up two return types, negative errno, and negative
> input.  User input of -22 shouldn't behave differently than -21, just
> because it happens to match -EINVAL.
> 
> Do we ever want to allow a negative return from cvtnum(), or should we
> just blindly map a negative int64_t into -ERANGE for a contract that we
> only accept 63-bit numbers?

Uggh. Maybe I should read qemu_strtosz_suffix() before making bogus
claims (and assuming that it is merely sugar for strtoll).

I stand corrected - the only time you return negative values is if
qemu_strtosz_suffx() populated an errno.

Reviewed-by: Eric Blake <eblake@redhat.com>

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]

  reply	other threads:[~2015-10-26 22:49 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-26 22:06 [Qemu-devel] [PATCH 0/3] qemu-io: clean up cvtnum usage John Snow
2015-10-26 22:06 ` [Qemu-devel] [PATCH 1/3] qemu-io: fix cvtnum lval types John Snow
2015-10-26 22:40   ` Eric Blake
2015-10-26 22:51     ` Eric Blake
2015-10-26 22:06 ` [Qemu-devel] [PATCH 2/3] qemu-io: Check for trailing chars John Snow
2015-10-26 22:44   ` Eric Blake
2015-10-26 22:49     ` Eric Blake [this message]
2015-10-26 22:06 ` [Qemu-devel] [PATCH 3/3] qemu-io: Correct error messages John Snow
2015-10-26 22:54   ` Eric Blake
2015-10-26 22:54     ` John Snow

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=562EADE7.5070102@redhat.com \
    --to=eblake@redhat.com \
    --cc=jsnow@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=mreitz@redhat.com \
    --cc=qemu-block@nongnu.org \
    --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).