|
|
Message-ID: <Pine.BSM.4.64L.2403211637580.19384@herc.mirbsd.org>
Date: Thu, 21 Mar 2024 16:41:58 +0000 (UTC)
From: Thorsten Glaser <tg@...bsd.de>
To: musl@...ts.openwall.com
Subject: Re: Potential bug in __res_msend_rc() wrt to union initialization.
Jₑₙₛ Gustedt dixit:
>As soon as you store
>to any member, padding bytes may change to arbitrary values.
Yes, but where is that a problem?
Something like:
union foo {
struct bar {
char *s;
size_t z;
} a;
struct baz {
size_t z;
char *s;
} b;
};
int
somefunc(int mode, char *buf, size_t len, …)
{
union foo u;
memset(u, '\0', sizeof(u));
/* … */
if (mode) {
/* from here on, u is decided to be a */
u.a.s = NULL;
} else {
/* from here on, u is decided to be b */
u.b.s = NULL;
}
/* … some other processing … */
if (mode) {
u.a.s = buf;
u.a.z = len;
} else {
u.b.s = buf;
u.b.z = len;
}
return (someotherfunc(&u, mode, …));
}
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.