From owner-dev-commits-src-main@freebsd.org Tue Jun 8 17:31:26 2021 Return-Path: Delivered-To: dev-commits-src-main@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 6BF5463B899; Tue, 8 Jun 2021 17:31:26 +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 4Fzy2k2Kgwz3t7j; Tue, 8 Jun 2021 17:31:26 +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 2595C5480; Tue, 8 Jun 2021 17:31:26 +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 158HVQ42037299; Tue, 8 Jun 2021 17:31:26 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 158HVQx5037285; Tue, 8 Jun 2021 17:31:26 GMT (envelope-from git) Date: Tue, 8 Jun 2021 17:31:26 GMT Message-Id: <202106081731.158HVQx5037285@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Jessica Clarke Subject: git: 6d2648bcaba9 - main - tip: Fix pointer-vs-integer confusion MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jrtc27 X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 6d2648bcaba9b14e2f5c76680f3e7608e1f125f4 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-main@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for the main branch of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 08 Jun 2021 17:31:26 -0000 The branch main has been updated by jrtc27: URL: https://cgit.FreeBSD.org/src/commit/?id=6d2648bcaba9b14e2f5c76680f3e7608e1f125f4 commit 6d2648bcaba9b14e2f5c76680f3e7608e1f125f4 Author: Jessica Clarke AuthorDate: 2021-06-08 17:30:59 +0000 Commit: Jessica Clarke CommitDate: 2021-06-08 17:30:59 +0000 tip: Fix pointer-vs-integer confusion Currently IREMOTE assumes that every value is (initially) a pointer to a long. This is true for NUMBERs, but false for STRINGs, which are instead pointers to pointers, though on ILP32 and LP64 systems these happen to have the same representation, but this is still a strict aliasing violation, and of course breaks on systems where the representations are not the same, such as CHERI. We do not currently have any BOOLs (short, curiously) or CHARs used with IREMOTE, though the code should not be relying on that. This removes the unused setaddress macro, and the now-unused address macro due to the above issue. Reviewed by: imp, kib Obtained from: CheriBSD Differential Revision: https://reviews.freebsd.org/D30697 --- usr.bin/tip/tip/tip.h | 2 -- usr.bin/tip/tip/value.c | 18 ++++++++++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/usr.bin/tip/tip/tip.h b/usr.bin/tip/tip/tip.h index 6bf94521cdfd..298b08cb6692 100644 --- a/usr.bin/tip/tip/tip.h +++ b/usr.bin/tip/tip/tip.h @@ -158,12 +158,10 @@ typedef #define number(v) ((long)(intptr_t)(v)) #define boolean(v) ((short)(intptr_t)(v)) #define character(v) ((char)(intptr_t)(v)) -#define address(v) ((long *)(v)) #define setnumber(v,n) do { (v) = (char *)(intptr_t)(n); } while (0) #define setboolean(v,n) do { (v) = (char *)(intptr_t)(n); } while (0) #define setcharacter(v,n) do { (v) = (char *)(intptr_t)(n); } while (0) -#define setaddress(v,n) do { (v) = (char *)(n); } while (0) /* * Escape command table definitions -- diff --git a/usr.bin/tip/tip/value.c b/usr.bin/tip/tip/value.c index a4776b80d35d..9cf1052d3ea2 100644 --- a/usr.bin/tip/tip/value.c +++ b/usr.bin/tip/tip/value.c @@ -69,8 +69,22 @@ vinit(void) if (p->v_type&ENVIRON) if ((cp = getenv(p->v_name))) p->v_value = cp; - if (p->v_type&IREMOTE) - setnumber(p->v_value, *address(p->v_value)); + if (p->v_type&IREMOTE) { + switch (p->v_type&TMASK) { + case STRING: + p->v_value = *(char **)p->v_value; + break; + case NUMBER: + setnumber(p->v_value, *(long *)p->v_value); + break; + case BOOL: + setboolean(p->v_value, *(short *)p->v_value); + break; + case CHAR: + setcharacter(p->v_value, *(char *)p->v_value); + break; + } + } } /* * Read the .tiprc file in the HOME directory