From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13487 invoked by alias); 2 Aug 2002 09:29:47 -0000 Mailing-List: contact libc-hacker-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-hacker-owner@sources.redhat.com Received: (qmail 13465 invoked from network); 2 Aug 2002 09:29:46 -0000 Received: from unknown (HELO md.dent.med.uni-muenchen.de) (138.245.179.2) by sources.redhat.com with SMTP; 2 Aug 2002 09:29:46 -0000 Received: (qmail 24680 invoked by uid 211); 2 Aug 2002 09:29:45 -0000 Date: Fri, 02 Aug 2002 02:29:00 -0000 Message-ID: <20020802092945.24679.qmail@md.dent.med.uni-muenchen.de> From: Wolfram Gloger To: libc-hacker@sources.redhat.com In-reply-to: <20020802004635.Y20867@sunsite.ms.mff.cuni.cz> (message from Jakub Jelinek on Fri, 2 Aug 2002 00:46:35 +0200) Subject: Re: [PATCH] xdr_array and calloc security fix References: <20020802004635.Y20867@sunsite.ms.mff.cuni.cz> X-SW-Source: 2002-08/txt/msg00013.txt.bz2 Hi, > + /* size_t is unsigned so the behavior on overflow is defined. */ > + bytes = n * elem_size; > + if (bytes / elem_size != n) { > + MALLOC_FAILURE_ACTION; > + return 0; > + } This is of course correct, but some (long) time ago I've measured that the cost for the division is quite noticeable, for say, the very common calloc(1, small_size). I've given up on being able to do this fast _and_ portably. Do we already have some system-specific mechanism to detect the rare overflow case for a 32bit-multiplication without having to perform a division? Regards, Wolfram.