Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <Pine.BSM.4.64L.2408011952370.23869@herc.mirbsd.org>
Date: Thu, 1 Aug 2024 20:00:14 +0000 (UTC)
From: Thorsten Glaser <tg@...bsd.de>
To: musl@...ts.openwall.com
Subject: Re: [PATCH 1/1] FD_SET() and FD_ISSET() warn on -Wsign-conversion

Brad House dixit:

>> #define FD_SET(d,s)	((s)->fds_bits[(0U + (d)) / (8 * sizeof(long))] |= \
>> 			    (1UL << ((0U + (d)) % (8 * sizeof(long)))))
>>
> Sorry it took me a while to reply on this.  But no, this doesn't resolve the
> issue, it still emits the same warning.

Mh. Thanks. Could always…

#define FD_SET(d,s) do {					\
	int FD_SET_fd = (d);					\
								\
	if (FD_SET_fd < 0 || FD_SET_fd >= FD_SETSIZE)		\
		abort();					\
	(s)->fds_bits[FD_SET_fd / (8 * sizeof(long))] |=	\
	    1UL << (FD_SET_fd % (8 * sizeof(long)));		\
} while (/* CONSTCOND */ 0)

… and, if there were¹ a suitable compile-time method to find out
whether a macro argument is a constant integer expression or not, use…
https://github.com/MirBSD/int/blob/6b2fe241e23bc52e428eb317bd531ce9cee2aea6/mbsdcc.h#L90-L98
… to force a compile-time abort if a constant value is out of range…

… but I can already hear dalias’ screams, so only half-kidding.

(Also, a library, even libc, calling abort(3) is usually bad taste,
although, perhaps, this is better, security-wise, than out-of-bounds
memory writes.)

Meow,
//mirabilos

① TTBOMK, there isn’t; famously, GCC’s
  __builtin_choose_expr(__builtin_constant_p(x), constbla(x), runtimebla(x))
  is utterly broken.
-- 
22:20⎜<asarch> The crazy that persists in his craziness becomes a master
22:21⎜<asarch> And the distance between the craziness and geniality is
only measured by the success 18:35⎜<asarch> "Psychotics are consistently
inconsistent. The essence of sanity is to be inconsistently inconsistent

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.