From patchwork Mon Jun 3 15:37:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 1109356 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=sourceware.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=libc-alpha-return-102408-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="FCg0MQtt"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 45HfMF3bGzz9s00 for ; Tue, 4 Jun 2019 01:37:45 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id:mime-version :content-type; q=dns; s=default; b=BeGMCzSIo5aE48FC/Jk/C9ZXzGcpl R4/ZBuCPtx7vpYXpWRIA0ebZtDhjTZr6XuH3RvBU1hmpBuYuKeXg51hERYZKswUS 4ZExychuDqLkh5KfngdYfXmtW3KjqrjTxLmJ8qVQo/In20mJ0l1O5JRqlXEu5fS7 zh1Bxvf6LYiuk0= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id:mime-version :content-type; s=default; bh=psrY3MywsNyV5TxiHmVU+JtCqq0=; b=FCg 0MQttiJdMJ4xoFPNQm+LAAph2zFsSd+DO4Ze/5/SMTegc7CBotendjE2CKP+mb0t 4786zqhZVaWIGvR6c5KOPpSShx5/ls/HrhWxAH8PJAYKrJlogflnUdkKcziHTsqA tQTOEEibAdYlyLvSMZKQgI9zUeEThFyXqERv/cbA= Received: (qmail 57174 invoked by alias); 3 Jun 2019 15:37:39 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 56184 invoked by uid 89); 3 Jun 2019 15:37:38 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-18.9 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_PASS autolearn=ham version=3.3.1 spammy= X-HELO: mx1.redhat.com From: Florian Weimer To: libc-alpha@sourceware.org Subject: [PATCH] dlfcn: Avoid one-element flexible array in Dl_serinfo Date: Mon, 03 Jun 2019 17:37:34 +0200 Message-ID: <87a7ey8ytd.fsf@oldenburg2.str.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.2 (gnu/linux) MIME-Version: 1.0 The dls_serpath path field, as an array of length 1, introduces unexpected array subscript checks with some compilers. GCC versions before 3.0 treat the nested anonymous union as a declaration of an unnamed type, and not as a member declaration, so this construct cannot be used for these compilers. 2019-06-03 Florian Weimer [BZ #24166] * dlfcn/dlfcn.h (Dl_serinfo): Do not use array of length 1 for dls_serpath field. diff --git a/dlfcn/dlfcn.h b/dlfcn/dlfcn.h index 896ad6fc9b..c550371999 100644 --- a/dlfcn/dlfcn.h +++ b/dlfcn/dlfcn.h @@ -180,7 +180,19 @@ typedef struct { size_t dls_size; /* Size in bytes of the whole buffer. */ unsigned int dls_cnt; /* Number of elements in `dls_serpath'. */ +# if __GNUC_PREREQ (3, 0) + /* The zero-length array avoids an unwanted array subscript check by + the compiler, while the surrounding anonymous union preserves the + historic size of the type. At the time of writing, GNU C does + not support structs with flexible array members in unions. */ + __extension__ union + { + Dl_serpath dls_serpath[0]; /* Actually longer, dls_cnt elements. */ + Dl_serpath __dls_serpath_pad[1]; + }; +# else Dl_serpath dls_serpath[1]; /* Actually longer, dls_cnt elements. */ +# endif } Dl_serinfo; #endif /* __USE_GNU */