mailing list of musl libc
 help / color / mirror / code / Atom feed
From: "Jₑₙₛ Gustedt" <jens.gustedt@inria.fr>
To: Thorsten Glaser <tg@mirbsd.de>
Cc: musl@lists.openwall.com
Subject: Re: [musl] Potential bug in __res_msend_rc() wrt to union initialization.
Date: Thu, 21 Mar 2024 11:58:06 +0100	[thread overview]
Message-ID: <20240321115806.511a81cc@inria.fr> (raw)
In-Reply-To: <Pine.BSM.4.64L.2403192046020.21682@herc.mirbsd.org>

Hi,

on Tue, 19 Mar 2024 20:47:00 +0000 (UTC) you (Thorsten Glaser
<tg@mirbsd.de>) wrote:

> Jₑₙₛ Gustedt dixit:
> 
> >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  
> 
> But then you can just memset the union and then initialise any
> known pointer members to NULL/nullptr manually afterwards in the
> union’s member you actually need.
> 
> (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ₑₙₛ

-- 
:: ICube :::::::::::::::::::::::::::::: deputy director ::
:: Université de Strasbourg :::::::::::::::::::::: ICPS ::
:: INRIA Nancy Grand Est :::::::::::::::::::::::: Camus ::
:: :::::::::::::::::::::::::::::::::::: ☎ +33 368854536 ::
:: https://icube-icps.unistra.fr/index.php/Jens_Gustedt ::

  reply	other threads:[~2024-03-21 10:58 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-18 19:56 Mike Cui
2024-03-18 21:34 ` Rich Felker
2024-03-18 22:22   ` NRK
2024-03-18 22:39     ` [musl] Potential bug in __res_msend_rc() wrt to union initialisation Thorsten Glaser
2024-03-19  0:01     ` [musl] Potential bug in __res_msend_rc() wrt to union initialization Mike Cui
2024-03-19 13:18       ` Rich Felker
2024-03-19 15:04         ` Mike Cui
2024-03-19 15:42           ` Rich Felker
2024-03-19 15:55             ` Mike Cui
2024-03-19 16:08               ` Rich Felker
2024-03-19 16:39                 ` Jₑₙₛ Gustedt
2024-03-19 20:47                   ` Thorsten Glaser
2024-03-21 10:58                     ` Jₑₙₛ Gustedt [this message]
2024-03-21 16:41                       ` Thorsten Glaser
2024-03-19 21:04                   ` NRK
2024-03-19 21:36                     ` Rich Felker
2024-03-20 17:11                       ` NRK

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240321115806.511a81cc@inria.fr \
    --to=jens.gustedt@inria.fr \
    --cc=musl@lists.openwall.com \
    --cc=tg@mirbsd.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).