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

* 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.

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.