From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/11229 Path: news.gmane.org!.POSTED!not-for-mail From: Pascal Cuoq Newsgroups: gmane.linux.lib.musl.general Subject: *scanf, wrong types in va_arg, and strict aliasing Date: Mon, 10 Apr 2017 09:31:48 +0000 Message-ID: <467D90DF-11E7-4E58-91A2-C5BFC71EE7F3@trust-in-soft.com> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable X-Trace: blaine.gmane.org 1491816708 8897 195.159.176.226 (10 Apr 2017 09:31:48 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 10 Apr 2017 09:31:48 +0000 (UTC) To: "musl@lists.openwall.com" Original-X-From: musl-return-11244-gllmg-musl=m.gmane.org@lists.openwall.com Mon Apr 10 11:31:42 2017 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.84_2) (envelope-from ) id 1cxVfi-0002Aw-2U for gllmg-musl@m.gmane.org; Mon, 10 Apr 2017 11:31:42 +0200 Original-Received: (qmail 1770 invoked by uid 550); 10 Apr 2017 09:31:44 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 1736 invoked from network); 10 Apr 2017 09:31:43 -0000 Thread-Topic: *scanf, wrong types in va_arg, and strict aliasing Thread-Index: AQHSsd1HI1wzCsuBhki9rDXmeaaEkQ== Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-messagesentrepresentingtype: 1 x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [90.92.141.252] Content-ID: Xref: news.gmane.org gmane.linux.lib.musl.general:11229 Archived-At: Hello again, the scanf implementation does the same thing as the printf implementation, = in vfscanf.c, line 110: https://git.musl-libc.org/cgit/musl/tree/src/stdio/vfscanf.c?id=3D54807d47a= cecab778498ced88ce8f62bfa16e379#n110 This line is eventually reached, for instance, for the snippet: int n; sscanf("0", "%d", &n); And the argument being consumed has type int*. This is not a case that 7.16= .1.1:2 allows. Besides, since I am reviewing this file, and since I was originally interes= ted in analyzing it for strict aliasing violations (although the analyzer i= s not ready to handle this file), I should point out the function store_int= at line 22 and the way it is used at line 146: https://git.musl-libc.org/cgit/musl/tree/src/stdio/vfscanf.c?id=3D54807d47a= cecab778498ced88ce8f62bfa16e379#n22 https://git.musl-libc.org/cgit/musl/tree/src/stdio/vfscanf.c?id=3D54807d47a= cecab778498ced88ce8f62bfa16e379#n146 This will not go down well with the strict aliasing analyzer, when it is fi= nally ready for this sort of code. And indeed, compiling the previous scanf= snippet together with musl's source code while enabling link-time optimiza= tion could plausibly produce non-working binary code because of the type-ba= sed alias analysis. For this latter problem, use of types with the may_alias attribute will fix= it for GCC and Clang. For the problem with va_arg, I do not see any easy w= ay out. It might be possible to write a longer version that a modern compil= er miraculously recognizes as doing the same thing over and over and folds = back into a single sequence of instructions, but without having tried it ye= t, this seems a bit far-fetched. Pascal