From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS31976 209.132.180.0/23 X-Spam-Status: No, score=-4.6 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD shortcircuit=no autolearn=ham autolearn_force=no version=3.4.0 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by dcvr.yhbt.net (Postfix) with ESMTP id 5DF4520705 for ; Thu, 8 Sep 2016 17:03:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S966199AbcIHRDz (ORCPT ); Thu, 8 Sep 2016 13:03:55 -0400 Received: from pb-smtp1.pobox.com ([64.147.108.70]:64729 "EHLO sasl.smtp.pobox.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S966061AbcIHRDy (ORCPT ); Thu, 8 Sep 2016 13:03:54 -0400 Received: from sasl.smtp.pobox.com (unknown [127.0.0.1]) by pb-smtp1.pobox.com (Postfix) with ESMTP id A8A7E3C5CD; Thu, 8 Sep 2016 13:03:53 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=from:to:cc :subject:references:date:in-reply-to:message-id:mime-version :content-type; s=sasl; bh=jkq8GopacOaDh7Vwtv+vuk2c09M=; b=JVRx5b iEjm7e1qY9Xnn4Lat4MexgHs6A8/I0j0yWUPtQdJ/sDzUzz0XMlMXcGaRN4c5qMI idCLOA+80W499WlqW+gaYnl2Jn1pUzZLl/Fnlv8ePWSsVYTU/s01b0mw/82rche/ jQzK4lQbcAn9QshVFSOQNn2dFXKW6APcBaxpo= DomainKey-Signature: a=rsa-sha1; c=nofws; d=pobox.com; h=from:to:cc :subject:references:date:in-reply-to:message-id:mime-version :content-type; q=dns; s=sasl; b=uciRyvZx4+M+3SPTcahQoS2Yc6G5fwK4 /4uvWP85dKd2p/ZVnnpQ5IFrSfh/9H+ZmhvIKyi3ai/pDeAZlqTtwtBV3yXr75Y3 DK959yZGRV9nfCpDDLELZ/0dwvPK85Y07NyGJmT2w3aS3wD1I2/JyDoSxXBDURjO k8rjvV5y0o0= Received: from pb-smtp1.nyi.icgroup.com (unknown [127.0.0.1]) by pb-smtp1.pobox.com (Postfix) with ESMTP id A011C3C5CC; Thu, 8 Sep 2016 13:03:53 -0400 (EDT) Received: from pobox.com (unknown [104.132.0.95]) (using TLSv1.2 with cipher DHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) by pb-smtp1.pobox.com (Postfix) with ESMTPSA id 22FED3C5CB; Thu, 8 Sep 2016 13:03:53 -0400 (EDT) From: Junio C Hamano To: Johannes Schindelin Cc: git@vger.kernel.org, Jeff King Subject: Re: [PATCH v3 2/3] Introduce a function to run regexec() on non-NUL-terminated buffers References: <94ee698b2736929d37640012a1b1735b134dd3d6.1473321437.git.johannes.schindelin@gmx.de> Importance: high Date: Thu, 08 Sep 2016 10:03:51 -0700 In-Reply-To: <94ee698b2736929d37640012a1b1735b134dd3d6.1473321437.git.johannes.schindelin@gmx.de> (Johannes Schindelin's message of "Thu, 8 Sep 2016 09:58:35 +0200 (CEST)") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Pobox-Relay-ID: 38760D0A-75E6-11E6-B155-F7BB12518317-77302942!pb-smtp1.pobox.com Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Johannes Schindelin writes: > We just introduced a test that demonstrates that our sloppy use of > regexec() on a mmap()ed area can result in incorrect results or even > hard crashes. > > So what we need to fix this is a function that calls regexec() on a > length-delimited, rather than a NUL-terminated, string. > > Happily, there is an extension to regexec() introduced by the NetBSD > project and present in all major regex implementation including > Linux', MacOSX' and the one Git includes in compat/regex/: by using > the (non-POSIX) REG_STARTEND flag, it is possible to tell the > regexec() function that it should only look at the offsets between > pmatch[0].rm_so and pmatch[0].rm_eo. > > That is exactly what we need. Yes, that is good. > Since support for REG_STARTEND is so widespread by now, let's just > introduce a helper function that uses it, and fall back to allocating > and constructing a NUL-terminated when REG_STARTEND is not available. I do not think this fallback is good; we do ship a compat/ fallback that does support REG_STARTEND and you'd want to use that. Not having the copying fallback means you do not even have to worry about the size+1 overflow and fix it with xmallocz() ;-)