From owner-svn-src-head@FreeBSD.ORG Mon May 5 22:20:05 2014 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 9A9BED7 for ; Mon, 5 May 2014 22:20:05 +0000 (UTC) Received: from mail-pa0-f49.google.com (mail-pa0-f49.google.com [209.85.220.49]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 6B32FBF5 for ; Mon, 5 May 2014 22:20:05 +0000 (UTC) Received: by mail-pa0-f49.google.com with SMTP id lj1so5010952pab.22 for ; Mon, 05 May 2014 15:19:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:content-type:mime-version:subject:from :in-reply-to:date:cc:content-transfer-encoding:message-id:references :to; bh=Evw6yi28scFhgS+JMehy9SpPct7EFvcCv7cA8GAC6ic=; b=kc4vnP/bXb8C6bCw6CefwvxTpnhVBfjXWJo312MAKBBqAbT97M8rWpX40MDSQKzJvE N9tSU5neRkyPyI+eMoJQx7wNIvp8xp5fxtZaXuQuhXigW8RIus0MPt+rUMu049lLh4ss XqgPn+Gr9YUGCzdWJ5WORp7HeJNP1ktu0AnABm+ywAChN/OmTU74WDs5OJHOklOfcTQn JhJrJutOhmrcBIXuIjtgHwAh1u6d1syGBNY0/3tmGiUUxIxOgXLHkImnocV6zkiu/3PL mhRKnhiXz9rLOlAdglEe0D4RjmgESuKbpPHIIgpsn0FPpBXIZRFrclrw9hl6h89rkhSl QL0g== X-Gm-Message-State: ALoCoQkHbln/iMcv2knQAZOtdDvOoExIku+FTPKq4dFpj6c0rKUS65C0D0+wMrOwSPgxgaaNi2Km X-Received: by 10.66.252.69 with SMTP id zq5mr77861427pac.54.1399328398860; Mon, 05 May 2014 15:19:58 -0700 (PDT) Received: from [10.64.26.239] (dc1-prod.netflix.com. [69.53.236.251]) by mx.google.com with ESMTPSA id ai11sm28636978pac.30.2014.05.05.15.19.57 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 05 May 2014 15:19:58 -0700 (PDT) Sender: Warner Losh X-Google-Original-From: Warner Losh Content-Type: text/plain; charset=iso-8859-1 Mime-Version: 1.0 (Mac OS X Mail 7.2 \(1874\)) Subject: Re: svn commit: r265367 - head/lib/libc/regex From: Warner Losh In-Reply-To: <53680C72.10809@FreeBSD.org> Date: Mon, 5 May 2014 16:19:54 -0600 Content-Transfer-Encoding: quoted-printable Message-Id: <04AFAEF4-1AF7-4310-9248-8654B1EAA560@gmail.com> References: <201405051641.s45GfFje086423@svn.freebsd.org> <5367CD77.40909@freebsd.org> <5367EB54.1080109@FreeBSD.org> <3C7CFFB7-5C84-4AC1-9A81-C718D184E87B@FreeBSD.org> <53680C72.10809@FreeBSD.org> To: Pedro Giffuni X-Mailer: Apple Mail (2.1874) Cc: svn-src-head@freebsd.org, Andrey Chernov , svn-src-all@freebsd.org, src-committers@freebsd.org, David Chisnall X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 05 May 2014 22:20:05 -0000 On May 5, 2014, at 4:10 PM, Pedro Giffuni wrote: > El 5/5/2014 4:21 PM, David Chisnall escribi=F3: >> On 5 May 2014, at 20:49, Pedro Giffuni wrote: >>=20 >>> Yes, but I reverted it because there are other ways to check for = overflows without the performance hit. >>=20 >=20 > FWIW, in this particular case I think the overflow simply doesn't = happen: apparently it is easier to be hit by a DoS first. >=20 >=20 >> Do we have a good reusable routine for doing this somewhere? Clang = and gcc both have some idiom recognisers that try to spot when people = are attempting to do this. Clang also has a builtin, which would be = good to use when available. Overflow checking is very cheap on modern = CPUs (add, branch on carry), so it would be nice if we could start = looking for this malloc() and realloc() pattern and replacing the = multiply with something that checks for the error. >>=20 >=20 > We don't. OpenBSD introduced an extension: reallocarray(). We do. reallocf(), which first appeared in FreeBSD 3.0. Warner