From owner-dev-commits-src-all@freebsd.org Wed Sep 15 23:59:53 2021 Return-Path: Delivered-To: dev-commits-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id D6297670B18; Wed, 15 Sep 2021 23:59:53 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4H8xzF3LYWz3mtZ; Wed, 15 Sep 2021 23:59:53 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4CC5C172EF; Wed, 15 Sep 2021 23:59:53 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 18FNxrLO011173; Wed, 15 Sep 2021 23:59:53 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 18FNxr2N011172; Wed, 15 Sep 2021 23:59:53 GMT (envelope-from git) Date: Wed, 15 Sep 2021 23:59:53 GMT Message-Id: <202109152359.18FNxr2N011172@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Piotr Pawel Stefaniak Subject: git: 2171b2cbe084 - main - diff: avoid applying offsets to null pointer MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: pstef X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 2171b2cbe084118e0e8f7de658f0302d0feb8827 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-all@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for all branches of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 15 Sep 2021 23:59:54 -0000 The branch main has been updated by pstef: URL: https://cgit.FreeBSD.org/src/commit/?id=2171b2cbe084118e0e8f7de658f0302d0feb8827 commit 2171b2cbe084118e0e8f7de658f0302d0feb8827 Author: Piotr Pawel Stefaniak AuthorDate: 2021-09-05 16:59:08 +0000 Commit: Piotr Pawel Stefaniak CommitDate: 2021-09-15 23:46:44 +0000 diff: avoid applying offsets to null pointer This was the only instance of undefined behavior I could find so far. --- usr.bin/diff/diffreg.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/usr.bin/diff/diffreg.c b/usr.bin/diff/diffreg.c index c743c862f2d6..4a00aff9243b 100644 --- a/usr.bin/diff/diffreg.c +++ b/usr.bin/diff/diffreg.c @@ -255,7 +255,6 @@ diffreg(char *file1, char *file2, int flags, int capsicum) anychange = 0; lastline = 0; lastmatchline = 0; - context_vec_ptr = context_vec_start - 1; /* * hw excludes padding and make sure when -t is not used, @@ -1050,8 +1049,12 @@ proceed: /* * Allocate change records as needed. */ - if (context_vec_ptr == context_vec_end - 1) { - ptrdiff_t offset = context_vec_ptr - context_vec_start; + if (context_vec_start == NULL || + context_vec_ptr == context_vec_end - 1) { + ptrdiff_t offset = -1; + + if (context_vec_start != NULL) + offset = context_vec_ptr - context_vec_start; max_context <<= 1; context_vec_start = xreallocarray(context_vec_start, max_context, sizeof(*context_vec_start));