[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH v7 2/5] sockets: Change inet_parse() to accept a
From: |
Kevin Wolf |
Subject: |
Re: [Qemu-devel] [PATCH v7 2/5] sockets: Change inet_parse() to accept address specification without port |
Date: |
Tue, 18 Sep 2012 16:08:43 +0200 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:13.0) Gecko/20120605 Thunderbird/13.0 |
Am 18.09.2012 15:31, schrieb Paolo Bonzini:
> Il 18/09/2012 15:22, Kevin Wolf ha scritto:
>> Am 17.09.2012 17:23, schrieb Bharata B Rao:
>>> sockets: Change inet_parse() to accept address specification without port
>>>
>>> From: Bharata B Rao <address@hidden>
>>>
>>> inet_parse() expects address:port. Change it to work without explicit port
>>> specification. In addition, don't depend solely on the return value of
>>
>> Things like "in addition" in a commit message are almost always a sign
>> that the patch should be split in two.
>>
>>> sscanf but also consider the value obtained for %n directive used in sscanf.
>>> This ensures that the scanning of malformed inet address isn't flagged as
>>> success.
>>
>> Can you give an example string that would be falsely accepted? To me the
>> old checks look fine (even though the new ones are a little bit easier
>> to read, so even if they don't fix anything, they might be worth doing).
>
> "localhost" would fail to be parsed:
>
> - if (2 != sscanf(str,"%64[^:]:%32[^,]%n",addr,port,&pos)) {
> + ret = sscanf(str, "%64[^:]%n:%32[^,]%n", addr, &addr_pos,
> + port, &port_pos);
> + if (addr_pos == -1 || ret == EOF) {
>
> because the : in the format string would not match and sscanf would
> return 1.
Yes, that's the part with making the port optional.
Bharata also claims that "scanning of malformed inet address" could
falsely succeed before, which I can't see (but which I suspect is what
the first two hunks of the patch are meant to address).
> However, is it correct to set the port unconditionally to an empty
> string? Your usecase makes sense, but perhaps the default port be
> passed as an extra parameter to inet_parse instead.
I thought about this, too, but didn't care enough to mention it. Now
that we're two, yes, I'd like adding a default port parameter.
Kevin
[Qemu-devel] [PATCH v7 3/5] aio: Fix qemu_aio_wait() to maintain correct walking_handlers count, Bharata B Rao, 2012/09/17
[Qemu-devel] [PATCH v7 4/5] configure: Add a config option for GlusterFS as block backend, Bharata B Rao, 2012/09/17
[Qemu-devel] [PATCH v7 5/5] block: Support GlusterFS as a QEMU block backend., Bharata B Rao, 2012/09/17