From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 Received: from second.openwall.net (second.openwall.net [193.110.157.125]) by inbox.vuxu.org (Postfix) with SMTP id 807B1234F0 for ; Thu, 21 Mar 2024 11:58:20 +0100 (CET) Received: (qmail 13555 invoked by uid 550); 21 Mar 2024 10:53:45 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: musl@lists.openwall.com Received: (qmail 13523 invoked from network); 21 Mar 2024 10:53:44 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=inria.fr; s=dc; h=date:from:to:cc:subject:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=fiJjbwlDR4IJkVL/vSWXsEN8CkYMuRIxi7egzIA4zUY=; b=HGoUMuS4o0f3DLOdxKFLyUOBWLadLIF1Zp2t7wd6tJbJNLZm8FgJl/65 zI5X5aauEjEutP6ZAgc40+Fp+7N2ucu4QZXk1Jba4rpYkITnDpQp/PBNk SXrXXCLF8MJa7NiP+jxuPLpkO76srRyXQIH3eXPpSH7yDK5edYfCxeVw8 8=; Authentication-Results: mail2-relais-roc.national.inria.fr; dkim=none (message not signed) header.i=none; spf=SoftFail smtp.mailfrom=jens.gustedt@inria.fr; dmarc=fail (p=none dis=none) d=inria.fr X-IronPort-AV: E=Sophos;i="6.07,142,1708383600"; d="scan'208";a="157789256" Date: Thu, 21 Mar 2024 11:58:06 +0100 From: =?UTF-8?B?SuKCkeKCmeKCmw==?= Gustedt To: Thorsten Glaser Cc: musl@lists.openwall.com Message-ID: <20240321115806.511a81cc@inria.fr> In-Reply-To: References: <20240318213441.GH4163@brightrain.aerifal.cx> <627epdel4gidvu46u5ua2mclieqy3wwqbs7sxjgtgrsmkvn4up@ehu5ru6micnr> <20240319131833.GI4163@brightrain.aerifal.cx> <20240319154222.GK4163@brightrain.aerifal.cx> <20240319160832.GL4163@brightrain.aerifal.cx> <20240319173930.57b8eb30@inria.fr> Organization: inria.fr X-Mailer: Claws Mail 4.0.0 (GTK+ 3.24.33; x86_64-pc-linux-gnu) X-Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAAXNSR0IArs4c6QAAACRQTFRFERslNjAsLTE9Ok9wUk9TaUs8iWhSrYZkj42Rz6aD3sGZ MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [musl] Potential bug in __res_msend_rc() wrt to union initialization. Hi, on Tue, 19 Mar 2024 20:47:00 +0000 (UTC) you (Thorsten Glaser ) wrote: > J=E2=82=91=E2=82=99=E2=82=9B Gustedt dixit: >=20 > >seems to be to always put the biggest union member first, or to even > >add an artificial first one `char [size-of-the-union] __dummy;`, such > >that this is always 0-byte initialized if there is any > >initialization =20 >=20 > But then you can just memset the union and then initialise any > known pointer members to NULL/nullptr manually afterwards in the > union=E2=80=99s member you actually need. >=20 > (IIRC, POSIX actively specifies the possible pointer members in > these structs for that reason.) no, that is actually not a full solution, I think. As soon as you store to any member, padding bytes may change to arbitrary values. I don't know if compilers really do that, but for example writing a wide register that has garbage in the upper half could be valid in some cases. Also, I think that up-thread there was the idea that a statically initialized object could be used to initialize an automatic object, and that this would guarantee that the padding is transferred. There is no such guarantee. So if you have known places where the pointer members are situated, you could try to ensure that you have an artificial union member as first, that has pointers at these places and otherwise fills the gaps with `unsigned char[something]`. That would guarantee that initialization does the right thing for pointer members, that all other bytes are zero-initialized, *and* that these values would be properly transferred on union assignment. Thanks J=E2=82=91=E2=82=99=E2=82=9B --=20 :: ICube :::::::::::::::::::::::::::::: deputy director :: :: Universit=C3=A9 de Strasbourg :::::::::::::::::::::: ICPS :: :: INRIA Nancy Grand Est :::::::::::::::::::::::: Camus :: :: :::::::::::::::::::::::::::::::::::: =E2=98=8E +33 368854536 :: :: https://icube-icps.unistra.fr/index.php/Jens_Gustedt ::