From owner-svn-src-all@freebsd.org Thu Apr 21 02:17:10 2016 Return-Path: Delivered-To: svn-src-all@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 68BC7B175D5 for ; Thu, 21 Apr 2016 02:17:10 +0000 (UTC) (envelope-from mailing-machine@vniz.net) Received: from mail-lf0-f68.google.com (mail-lf0-f68.google.com [209.85.215.68]) (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 F1C111FEA for ; Thu, 21 Apr 2016 02:17:09 +0000 (UTC) (envelope-from mailing-machine@vniz.net) Received: by mail-lf0-f68.google.com with SMTP id o124so6795020lfb.2 for ; Wed, 20 Apr 2016 19:17:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=/E5o9fctubXEWf6L0MhEzi0iY18M2RAyZmRYzpj8pW0=; b=OleE2DiZTkgjOwc6feocvFil06F9efCeaMWUF5TN3jgVeyCng30AR4Qays2WR+uGaW nxTLZfw1pbPF6Fy86T+c8vZCpdwhnddf6twLMbwimWGowrLLSBE/S3Rw7gq799Q0lJ0u v6iQKhp9/JbPdsb21RxD+hBVC1Itr+3HgKJL3gyF1KQ9vfEzAEuI4E7zI/fhMZC7oGaB g9lQ0eE82Ed2+IppwGvjbsYKNuPoxq9qX5fUpTktoQYV4w/aLuF/kmWY9wjigUZAUUXR uhKhT34wDHGnUjS/JvhCu7pjP6ydRS66gM8znGX33jlSHReL43WyYAEXm9hwaKIwuPjl qxsQ== X-Gm-Message-State: AOPr4FXxegLtMI43eqM5FHwl+Pi5LkD4QKQcQKfjxJvuNcdG8/BMszDDF33UgW0Aw6pXog== X-Received: by 10.25.161.17 with SMTP id k17mr4273380lfe.61.1461204022391; Wed, 20 Apr 2016 19:00:22 -0700 (PDT) Received: from [192.168.1.2] ([89.169.173.68]) by smtp.gmail.com with ESMTPSA id o66sm55624lfg.32.2016.04.20.19.00.21 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 20 Apr 2016 19:00:21 -0700 (PDT) Subject: Re: svn commit: r298367 - head/lib/libc/locale To: Baptiste Daroussin , src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org References: <201604202044.u3KKiUMq081452@repo.freebsd.org> From: Andrey Chernov Message-ID: Date: Thu, 21 Apr 2016 05:00:20 +0300 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 21 Apr 2016 02:17:10 -0000 On 21.04.2016 3:57, Andrey Chernov wrote: > On 20.04.2016 23:44, Baptiste Daroussin wrote: >> Author: bapt >> Date: Wed Apr 20 20:44:30 2016 >> New Revision: 298367 >> URL: https://svnweb.freebsd.org/changeset/base/298367 >> >> Log: >> Check the returned value of memchr(3) before using it >> >> Reported by: Coverity >> CID: 1338530 >> >> Modified: >> head/lib/libc/locale/ascii.c >> >> Modified: head/lib/libc/locale/ascii.c >> ============================================================================== >> --- head/lib/libc/locale/ascii.c Wed Apr 20 20:43:05 2016 (r298366) >> +++ head/lib/libc/locale/ascii.c Wed Apr 20 20:44:30 2016 (r298367) >> @@ -133,11 +133,14 @@ _ascii_mbsnrtowcs(wchar_t * __restrict d >> >> if (dst == NULL) { >> s = memchr(*src, '\0', nms); >> + if (s == NULL) >> + return (nms); >> + >> if (*s & 0x80) { >> errno = EILSEQ; >> return ((size_t)-1); >> } >> - return (s != NULL ? s - *src : nms); >> + return (s - *src); >> } >> >> s = *src; >> > > The whole code is incorrect, only the very first char is checked, there > must be a loop like in -stable: > > if (dst == NULL) { > for (s = *src; nms > 0 && *s != '\0'; s++, nms--) { > if (*s & 0x80) { > errno = EILSEQ; > return ((size_t)-1); > } > } > return (s - *src); > } > > Since svn history is lost on deleting, I don't know why incorrect > version was committed. > Typo, the very first == the very last, i.e. only NUL char is checked which always pass.