lists.openwall.net | lists / announce owl-users owl-dev john-users john-dev passwdqc-users yescrypt popa3d-users / oss-security kernel-hardening musl sabotage tlsify passwords / crypt-dev xvendor / Bugtraq Full-Disclosure linux-kernel linux-netdev linux-ext4 linux-hardening linux-cve-announce PHC | |
Open Source and information security mailing list archives
| ||
|
Date: Fri, 20 May 2022 06:19:15 +0200 From: Willy Tarreau <w@....eu> To: Ammar Faizi <ammarfaizi2@...weeb.org> Cc: "Paul E. McKenney" <paulmck@...nel.org>, Alviro Iskandar Setiawan <alviro.iskandar@...weeb.org>, Linux Kernel Mailing List <linux-kernel@...r.kernel.org>, GNU/Weeb Mailing List <gwml@...r.gnuweeb.org>, Facebook Kernel Team <kernel-team@...com> Subject: Re: [PATCH v1 1/2] tools/nolibc/stdlib: Support overflow checking for older compiler versions Hi Ammar, On Fri, May 20, 2022 at 12:21:15AM +0700, Ammar Faizi wrote: > diff --git a/tools/include/nolibc/stdlib.h b/tools/include/nolibc/stdlib.h > index 8fd32eaf8037..92378c4b9660 100644 > --- a/tools/include/nolibc/stdlib.h > +++ b/tools/include/nolibc/stdlib.h > @@ -128,10 +128,9 @@ void *malloc(size_t len) > static __attribute__((unused)) > void *calloc(size_t size, size_t nmemb) > { > - void *orig; > - size_t res = 0; > + size_t x = size * nmemb; > > - if (__builtin_expect(__builtin_mul_overflow(nmemb, size, &res), 0)) { > + if (__builtin_expect(size && ((x / size) != nmemb), 0)) { Ah, that approach is even better than mine, I'm seeing that on x86 the compiler simply checks the overflow flag after the multiply, that's perfect! Acked-by: Willy Tarreau <w@....eu> Willy
Powered by blists - more mailing lists