From owner-freebsd-net@FreeBSD.ORG Wed Feb 11 13:15:50 2009 Return-Path: Delivered-To: net@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id E94211065677 for ; Wed, 11 Feb 2009 13:15:50 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from mail.terabit.net.ua (mail.terabit.net.ua [195.137.202.147]) by mx1.freebsd.org (Postfix) with ESMTP id 87E9D8FC16 for ; Wed, 11 Feb 2009 13:15:50 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from skuns.zoral.com.ua ([91.193.166.194] helo=mail.zoral.com.ua) by mail.terabit.net.ua with esmtps (TLSv1:AES256-SHA:256) (Exim 4.63 (FreeBSD)) (envelope-from ) id 1LXE2f-000DCT-CI; Wed, 11 Feb 2009 14:18:13 +0200 Received: from deviant.kiev.zoral.com.ua (root@deviant.kiev.zoral.com.ua [10.1.1.148]) by mail.zoral.com.ua (8.14.2/8.14.2) with ESMTP id n1BCIAdg005733 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 11 Feb 2009 14:18:10 +0200 (EET) (envelope-from kostikbel@gmail.com) Received: from deviant.kiev.zoral.com.ua (kostik@localhost [127.0.0.1]) by deviant.kiev.zoral.com.ua (8.14.3/8.14.3) with ESMTP id n1BCIA94090339; Wed, 11 Feb 2009 14:18:10 +0200 (EET) (envelope-from kostikbel@gmail.com) Received: (from kostik@localhost) by deviant.kiev.zoral.com.ua (8.14.3/8.14.3/Submit) id n1BCIAb2090338; Wed, 11 Feb 2009 14:18:10 +0200 (EET) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: deviant.kiev.zoral.com.ua: kostik set sender to kostikbel@gmail.com using -f Date: Wed, 11 Feb 2009 14:18:10 +0200 From: Kostik Belousov To: Roman Divacky Message-ID: <20090211121810.GF62256@deviant.kiev.zoral.com.ua> References: <20090210215739.GA24102@freebsd.org> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="jkO+KyKz7TfD21mV" Content-Disposition: inline In-Reply-To: <20090210215739.GA24102@freebsd.org> User-Agent: Mutt/1.4.2.3i X-Virus-Scanned: ClamAV version 0.94.2, clamav-milter version 0.94.2 on skuns.kiev.zoral.com.ua X-Virus-Status: Clean X-Spam-Status: No, score=-4.4 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00, FB_WORD1_END_DOLLAR autolearn=ham version=3.2.5 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on skuns.kiev.zoral.com.ua X-Virus-Scanned: mail.terabit.net.ua 1LXE2f-000DCT-CI 19221fdbfb9eb02c8269edbc8a555a81 X-Terabit: YES Cc: mav@freebsd.org, net@freebsd.org Subject: Re: unsafe C in netgraph/pppoed.c X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 11 Feb 2009 13:15:54 -0000 --jkO+KyKz7TfD21mV Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Feb 10, 2009 at 10:57:39PM +0100, Roman Divacky wrote: > hi >=20 >=20 > struct pppoe_tag { > u_int16_t tag_type; > u_int16_t tag_len; > char tag_data[]; > }__packed; >=20 > struct pppoe_hdr{ > u_int8_t ver:4; > u_int8_t type:4; > u_int8_t code; > u_int16_t sid; > u_int16_t length; > struct pppoe_tag tag[]; > }__packed; >=20 >=20 > this is inherently unsafe as the tag_data can only have 0 elements > to be used safely. gcc compiles this without warning although there > should be a big one.=20 >=20 > I found this using clang, which produces this error/warning: >=20 > lev pppoed$ ccc -c pppoed.c = ccc: Unknown host 'freebsd', usin= g generic host information. > In file included from pppoed.c:41: > /usr/include/netgraph/ng_pppoe.h:213:22: error: 'struct pppoe_tag' may no= t be used as an array element due to flexible array member > struct pppoe_tag tag[]; > ^ > 1 diagnostic generated. >=20 > can you guys take a look at this issue? >=20 > thnx! >=20 > roman >=20 > p.s. please keep me CCed as I am not subscribed to net@ The use of [] as an array specifier for the last structure element is a well formed C99 construct, called flexible array member. See ISO/IEC 9899:1999 (E), 6.7.2.1, clause 16. Citation: As a special case, the last element of a structure with more than one named member may have an incomplete array type; this is called a flexible array member. =2E.. Then, the use of the structure with flexible array member as a member of another structure is the gcc extension. See the Chapter 5: Extensions to the C Language Family 5.14 Arrays of Length Zero in the gcc manual. This is the reason why it is silently adopted by in-tree compiler. --jkO+KyKz7TfD21mV Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (FreeBSD) iEYEARECAAYFAkmSwgEACgkQC3+MBN1Mb4gsHACg6ol3ASEzatcwyXgiiXqJ5N5V 0nYAoNhGSFYJadZIbxMsDha2GRBMelUb =oHhw -----END PGP SIGNATURE----- --jkO+KyKz7TfD21mV--