From owner-freebsd-current@freebsd.org Wed Jul 20 23:39:36 2016 Return-Path: Delivered-To: freebsd-current@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id B9558B9F193 for ; Wed, 20 Jul 2016 23:39:36 +0000 (UTC) (envelope-from darkuranium@gmail.com) Received: from mail-lf0-x231.google.com (mail-lf0-x231.google.com [IPv6:2a00:1450:4010:c07::231]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 3DABE1448 for ; Wed, 20 Jul 2016 23:39:36 +0000 (UTC) (envelope-from darkuranium@gmail.com) Received: by mail-lf0-x231.google.com with SMTP id g62so48658110lfe.3 for ; Wed, 20 Jul 2016 16:39:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-transfer-encoding; bh=Kv9qNEZ9MWjALOJtnQXpqBUlCbJ4cG+pGgeonQXhjcI=; b=ztcN9TD9o0C+646TcB2V1KuMtYdAW1/MWQeAxv7fZFLlkGTGlSMGDa/MMkT0/EubKs xsRVUOIG09ApFAAtmCmosZMmofw3SSdvbs0Kx9WLeY+cunxFhXuYqfMCH2zod96ZtJx0 AOaWfPj5TqiVrm1PMoybHWjbAj2ndewA+TbuzG1M6SeoR6FlnrIikqb2oBIaSq7bvm4T NkG1JtKdwDCy551CCpgPRsGVOC6vCFbnL8AC99/ne/VV7K10lGlJ2T/3xJn6bVBfqt1Y A9EdejCalycSv0YiBryfAyVKr11z8CVSCdGS0b2PxZeny+YiV6ZHdd4KPlT7yKh2be3h hhlA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:content-transfer-encoding; bh=Kv9qNEZ9MWjALOJtnQXpqBUlCbJ4cG+pGgeonQXhjcI=; b=GXAI6ePzjIOiMbwEjO/KfZGQOiJqwhwFRldWBasTRxQSfyeIlGnAoQDA8H5jyp1/bY 4cOtEBT4AbYI8RxvBTyjhZ8q3InHwFvxI4PCa4Zkf3+83QvN14a3NYcJcCBmq+Lm/k/u dsmHffYf2nm15bRT5TUSvnMc9Ad84c7CrEVqjFwcpwmOSWM8vv0nQutKajV8JXKiEJGE GZvFgaJeiMOIY/v0IDMJLrgoPu5SXpHw2I6gXigZBbBivjQJDbwaY/Uxw1gtvw+oxwc1 JFrTC4NbUybxmmEAJoC016nOs+XZE7P3yYWx1/Uh87Xi1SFqyxGFxSGww0qoio1W/61p raNg== X-Gm-Message-State: ALyK8tJhaBK39ITgAeWnwOUzRjhruFNtSK8ditjdAshU6FfTQ++oaMCboMtoHIUCvY2EQsLomvfsAE4nwbd+oQ== X-Received: by 10.25.10.208 with SMTP id 199mr20625423lfk.124.1469057973948; Wed, 20 Jul 2016 16:39:33 -0700 (PDT) MIME-Version: 1.0 Received: by 10.25.160.201 with HTTP; Wed, 20 Jul 2016 16:39:33 -0700 (PDT) In-Reply-To: References: <201607202023.u6KKNksl055230@gw.catspoiler.org> From: =?UTF-8?B?VGltIMSMYXM=?= Date: Thu, 21 Jul 2016 01:39:33 +0200 Message-ID: Subject: Re: UTF-8 by default? To: freebsd-current@freebsd.org Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 20 Jul 2016 23:39:36 -0000 I managed to find some time to have a closer look right now, and there isn't a problem with the `read(2)` (meaning it's a false positive). The code could use some cleanup for easier auditability (or maybe not ... "if it ain't broken, don't fix it!"), but it's otherwise not broken --- well, at least where Coverity reported the issue. On 21 July 2016 at 00:14, Tim =C4=8Cas wrote: > On 20 July 2016 at 22:23, Don Lewis wrote: >> It passes a fixed-length non-NUL terminated buffer (returned by read(2)) >> to mbrtowc(). In addition to the lack of termination, the buffer could >> also contain a partial character at its beginning or end if the contents >> are UTF-8. >> >> The Coverity ID is 978825. > > I don't have access to Coverity, but with boru's help, I managed to > check the lines. There is no problem as far as I can tell --- yes, the > buffer is not NUL-terminated [1], *BUT* `mbrtowc(3)` takes a `len` > argument (which is returned from said `read(2)`), so it never tries to > read out of scope [2,3]. > > The problem might still be elsewhere, though --- the code is somewhat > hairy, so I'll give it a closer check tomorrow. > > [1] https://svnweb.freebsd.org/base/head/usr.bin/wc/wc.c?view=3Dmarkup#l2= 77 > [2] https://svnweb.freebsd.org/base/head/usr.bin/wc/wc.c?view=3Dmarkup#l2= 90 > [3] `man 3 mbrtowc`