Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <87r08hw10x.fsf@alyssa.is>
Date: Tue, 15 Oct 2024 22:42:54 +0200
From: Alyssa Ross <hi@...ssa.is>
To: Florian Weimer <fw@...eb.enyo.de>
Cc: libc-coord@...ts.openwall.com
Subject: Re: sscanf("0x", "%x", &out)

Florian Weimer <fw@...eb.enyo.de> writes:

> * Alyssa Ross:
>
>> This returns 1 with Glibc, and 0 with musl:
>>
>> sscanf("0x", "%x", &out)
>>
>> (I'm talking about the return value, not the value of out.)
>>
>> This causes real world compatibility issues.  This test[1] fails,
>> because bluetoothctl expects sscanf("0x01", "%2hhx", …) to return 1, and
>> returns an error if it doesn't[2].
>>
>> So, what's the right thing to do here?  The C standard is too dense for
>> me.
>>
>> [1]: https://github.com/martinpitt/python-dbusmock/blob/1ae426c687ee48c92ba1a4e27778f217040d7180/tests/test_bluez5.py#L496
>> [2]: https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/client/adv_monitor.c?id=32e9d15a60948ad1e912f6660e9dea6d8c5265d1#n454
>
> I don't know how to interpret the C standard, but if I read this
> correctly the code parses "0x01" as two bytes, 0 followed by 1.  This
> doesn't look correct.  Clearly the expected input for the C code is of
> the the form "0001", and the 0x business is not really taken into
> account (otherwise it would parse 0x01 as a one-byte sequence).
> So the Python test looks incorrect.  And the C code leans towards
> expecting the musl behavior.

I think you're right that it's wrong to expect a 0x prefix to work, and
I've submitted a PR to change it[1], but I'm not familiar with this code
enough to know what it's trying to do.  In particular it confuses me
that other people seem to also expect this to work[2].  Maybe it's just
because other programs work that way?

[1]: https://github.com/martinpitt/python-dbusmock/pull/222
[2]: https://github.com/bluez/bluez/issues/901

Download attachment "signature.asc" of type "application/pgp-signature" (833 bytes)

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.